Skip to content

Commit

Permalink
chore(Typing): move locales to src, typed i18n IDs
Browse files Browse the repository at this point in the history
Typed i18n ID strings allow for controlled addition and modification of localization strings.
Also fixed linting issues and fully automized prettier + eslint.
  • Loading branch information
Garifullin Ruslan committed Dec 9, 2020
1 parent efdcdb0 commit bfc87b9
Show file tree
Hide file tree
Showing 60 changed files with 251 additions and 179 deletions.
113 changes: 69 additions & 44 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,106 @@
"es2020": true,
"node": true
},

"extends": [
"airbnb-base",
"prettier",
"prettier/@typescript-eslint"
],

"extends": ["airbnb-base", "prettier", "prettier/@typescript-eslint"],
"globals": {
"__BUILDNUM__": "readonly"
},

"parser": "@typescript-eslint/parser",

"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"project": "tsconfig.json"
},

"plugins": [
"@typescript-eslint"
],

"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-floating-promises": ["warn"],
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-unused-expressions": ["error"],
"@typescript-eslint/no-unused-vars": ["error"],
"curly": ["error", "all"],
"import/extensions": "off",
"arrow-parens": ["error", "always"],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "never"
}
],
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never"
}
],
"import/prefer-default-export": "off",
"no-bitwise": "off",
"no-console": "off",
"no-empty": "off",
"no-fallthrough": "off",
"no-multiple-empty-lines": "error",
"no-restricted-syntax": "off",
"no-shadow": "off", // Prevent conflicts with @typescript-eslint/no-shadow
"no-underscore-dangle": "off",
"no-void": ["error", { "allowAsStatement": true }],
"padding-line-between-statements": [ // See docs
"no-unused-expressions": "off", // @typescript-eslint/no-unused-expressions used instead
"no-void": [
"error",
{
"allowAsStatement": true
}
],
"padding-line-between-statements": [
// See docs
"warn",
{ "blankLine": "always", "prev": "*", "next": "return" }, // return

{ "blankLine": "always", "prev": "*", "next": "class" }, // class

{ "blankLine": "always", "prev": ["const", "let", "var"], "next": "*" }, // Variable declaration
{ "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"] },

{ "blankLine": "always", "prev": ["case", "default"], "next": "*" }, // case in switch

{ "blankLine": "always", "prev": "*", "next": ["try", "switch", "for", "block-like"] }, // blocks (try, switch, if, while, for, {})
{ "blankLine": "always", "prev": ["try", "switch", "for", "block-like"], "next": "*" },

{ // Multiline
{
"blankLine": "always",
"prev": "*",
"next": "return"
}, // return
{
"blankLine": "always",
"prev": "*",
"next": "class"
}, // class
{
"blankLine": "always",
"prev": ["const", "let", "var"],
"next": "*"
}, // Variable declaration
{
"blankLine": "any",
"prev": ["const", "let", "var"],
"next": ["const", "let", "var"]
},
{
"blankLine": "always",
"prev": ["case", "default"],
"next": "*"
}, // case in switch
{
"blankLine": "always",
"prev": "*",
"next": ["try", "switch", "for", "block-like"]
}, // blocks (try, switch, if, while, for, {})
{
"blankLine": "always",
"prev": ["try", "switch", "for", "block-like"],
"next": "*"
},
{
// Multiline
"blankLine": "always",
"prev": ["multiline-const", "multiline-expression", "multiline-let"],
"next": "*"
}
]
},

"settings": {
"import/resolver": {
"node": {
"paths": [
"src",
"worker",
"node_modules"
],

"extensions": [
".js",
".json",
".ts"
]
"paths": ["src", "worker", "node_modules"],
"extensions": [".js", ".json", ".ts"]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"singleQuote": true,
"trailingComma": "all",
"trailingComma": "es5",
"endOfLine": "lf",
"printWidth": 100,
"arrowParens": "avoid"
"arrowParens": "always"
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"start:debug": "qode --max-old-space-size=128 --inspect=0.0.0.0:9229 ./dist/index.js",
"start:watch": "nodemon -e js,ts,css,scss --ignore dist/ --ignore node_modules/ --exec npm run start:debug",
"lint": "eslint src/**/*.ts worker/**/*.ts",
"lint:fix": "npm run lint -- --fix && npm run prettier",
"lint:ts": "tsc -p .",
"lint:fix": "eslint --fix 'src/**/*.ts' 'worker/**/*.ts' && npm run prettier",
"prettier": "prettier --write --loglevel warn src/**/*.ts worker/**/*.ts src/**/*.scss",
"postinstall": "node ./downloadNodeGui.js && webpack -p",
"package": "nodegui-packer --pack ./dist",
Expand Down
2 changes: 1 addition & 1 deletion src/Tray.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QAction, QMenu, QSystemTrayIcon, QSystemTrayIconActivationReason } from '@nodegui/nodegui';
import { Constants } from 'discord.js';
import { __ } from 'i18n';
import { __ } from './utilities/StringProvider';
import { app } from '.';
import { Events as AppEvents } from './utilities/Events';

Expand Down
6 changes: 3 additions & 3 deletions src/components/DLabel/DLabel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CursorShape, QLabel, QPoint, TextInteractionFlag } from '@nodegui/nodegui';
import { DMChannel, Guild, GuildChannel, TextChannel } from 'discord.js';
import { __ } from 'i18n';
import open from 'open';
import { basename, extname } from 'path';
import { URL } from 'url';
import { __ } from '../../utilities/StringProvider';
import { app } from '../..';
import { Events } from '../../utilities/Events';
import { MarkdownStyles } from '../../utilities/MarkdownStyles';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class DLabel extends QLabel {
Events.OPEN_USER_PROFILE,
url.hostname,
app.currentGuildId,
this.mapToGlobal(this.p0),
this.mapToGlobal(this.p0)
);

break;
Expand Down Expand Up @@ -105,7 +105,7 @@ export class DLabel extends QLabel {
? `${__('EMOJI_POPOUT_JOINED_GUILD_EMOJI_DESCRIPTION')} <b>${serverName}</b>`
: __('EMOJI_POPOUT_PREMIUM_UNJOINED_PRIVATE_GUILD_DESCRIPTION')
}
</html>`,
</html>`
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DMPanel/DMTitleBar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { __ } from 'i18n';
import { __ } from '../../utilities/StringProvider';
import { DLineEdit } from '../DLineEdit/DLineEdit';
import { DTitleBar } from '../DTitleBar/DTitleBar';
import { DMUsersList } from './DMUsersList';
Expand Down
10 changes: 5 additions & 5 deletions src/components/EmojiPicker/EmojiPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { NativeRawPointer } from '@nodegui/nodegui/dist/lib/core/Component';
import { Emoji } from 'discord.js';
import { EventEmitter } from 'events';
import { __ } from 'i18n';
import { __ } from '../../utilities/StringProvider';
import { app } from '../..';
import { CancelToken } from '../../utilities/CancelToken';
import { createLogger } from '../../utilities/Console';
Expand Down Expand Up @@ -293,8 +293,8 @@ export class EmojiPicker extends QMenu {
emojiView.clear();
emojiView.setCurrentRow(0);

if (emojiName === __('SEARCH_FOR_EMOJI') && config.recentEmojis) {
const recents = config.recentEmojis.sort((a, b) => a[1] - b[1]);
if (emojiName === __('SEARCH_FOR_EMOJI') && config.get('recentEmojis')) {
const recents = config.get('recentEmojis').sort((a, b) => a[1] - b[1]);

for (const item of recents) {
const emoji = client.emojis.resolve(item[0]);
Expand All @@ -309,7 +309,7 @@ export class EmojiPicker extends QMenu {

const result = client.emojis.cache
.filter((emoji) =>
emoji.name.toLowerCase().includes(emojiName.replace(/ /g, '').toLowerCase()),
emoji.name.toLowerCase().includes(emojiName.replace(/ /g, '').toLowerCase())
)
.partition((v) => v.guild.id === app.currentGuildId);

Expand All @@ -332,7 +332,7 @@ export class EmojiPicker extends QMenu {

this.insertEmoji(
i < thisGuild.length ? thisGuild[i] : otherGuilds[i - thisGuild.length],
this.token,
this.token
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/GuildPanel/ChannelMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ChannelMembers extends QListWidget {
ubtn.setStyleSheet(
speaking.bitfield === 1
? '#Avatar { border: 2px solid #43b581; padding: 3px; border-radius: 12px; }'
: '',
: ''
);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/GuildPanel/ChannelsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class ChannelsList extends QListWidget {
.filter((c) => c.can(Permissions.FLAGS.VIEW_CHANNEL))
.partition((a) => a.type === 'category') as [
Collection<string, CategoryChannel>,
Collection<string, GuildChannel>,
Collection<string, GuildChannel>
];

debug(`Loading ${categories.size} categories...`);
Expand All @@ -219,7 +219,7 @@ export class ChannelsList extends QListWidget {
label.adjustSize();
label.addEventListener(
WidgetEventTypes.MouseButtonPress,
this.toggleCategory.bind(this, guild.id, category.id),
this.toggleCategory.bind(this, guild.id, category.id)
);

const item = new QListWidgetItem();
Expand Down
7 changes: 4 additions & 3 deletions src/components/GuildPanel/GuildActionsMenu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { QAction, QMenu, QPoint, WidgetAttribute, WidgetEventTypes } from '@nodegui/nodegui';
import { Guild } from 'discord.js';
import { __ } from 'i18n';
import { app } from '../..';
import { Events } from '../../utilities/Events';
import { PhraseID } from '../../utilities/PhraseID';
import { __ } from '../../utilities/StringProvider';
import { ViewOptions } from '../../views/ViewOptions';

export class GuildActionsMenu extends QMenu {
Expand Down Expand Up @@ -35,7 +36,7 @@ export class GuildActionsMenu extends QMenu {
this.addEventListener(WidgetEventTypes.Hide, () => this.updateComponents());
}

private addComponent(textId: string, callback: () => Promise<void>) {
private addComponent(textId: PhraseID, callback: () => Promise<void>) {
const item = new QAction();

item.setText(__(textId));
Expand Down Expand Up @@ -115,7 +116,7 @@ export class GuildActionsMenu extends QMenu {
.get('CHANGE_NICKNAME')
?.setProperty(
'visible',
member.hasPermission('CHANGE_NICKNAME') || member.hasPermission('MANAGE_NICKNAMES'),
member.hasPermission('CHANGE_NICKNAME') || member.hasPermission('MANAGE_NICKNAMES')
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/GuildPanel/GuildPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GuildPanel extends QWidget {
24,
24,
1,
1,
1
);

private guildow = new QLabel(this);
Expand Down Expand Up @@ -95,7 +95,7 @@ export class GuildPanel extends QWidget {
if (event?.button() === MouseButton.LeftButton) {
actionsMenu.popup(this.channelsList.mapToGlobal(new QPoint(0, 0)));
}
},
}
);

controls.setSpacing(0);
Expand Down
2 changes: 1 addition & 1 deletion src/components/GuildsList/GuildButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
WidgetEventTypes,
} from '@nodegui/nodegui';
import { Guild } from 'discord.js';
import { __ } from 'i18n';
import { __ } from '../../utilities/StringProvider';
import { app } from '../..';
import { Events } from '../../utilities/Events';
import { pictureWorker } from '../../utilities/PictureWorker';
Expand Down
2 changes: 1 addition & 1 deletion src/components/GuildsList/GuildsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
WidgetEventTypes,
} from '@nodegui/nodegui';
import { Client, Constants, DQConstants, Guild } from 'discord.js';
import { __ } from 'i18n';
import path from 'path';
import { app, MAX_QSIZE } from '../..';
import { Events as AppEvents } from '../../utilities/Events';
import { __ } from '../../utilities/StringProvider';
import { ViewOptions } from '../../views/ViewOptions';
import { GuildButton } from './GuildButton';

Expand Down
2 changes: 1 addition & 1 deletion src/components/InputPanel/AttachmentsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
QWidget,
WidgetEventTypes,
} from '@nodegui/nodegui';
import { __ } from 'i18n';
import { basename, extname, join } from 'path';
import { pathToFileURL } from 'url';
import { PIXMAP_EXTS } from '../..';
import { createLogger } from '../../utilities/Console';
import { pictureWorker } from '../../utilities/PictureWorker';
import { __ } from '../../utilities/StringProvider';

const { error } = createLogger('AttachmentsPanel');

Expand Down
Loading

0 comments on commit bfc87b9

Please sign in to comment.