Skip to content

Commit

Permalink
Update ESLint rules.
Browse files Browse the repository at this point in the history
• Move some rules to @Stylistic.
• Allow for empty catch blocks.
  • Loading branch information
SpacingBat3 committed May 2, 2024
1 parent bd078e5 commit dfb18b3
Show file tree
Hide file tree
Showing 3 changed files with 484 additions and 138 deletions.
258 changes: 120 additions & 138 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,146 +4,128 @@
"node": true,
"browser": true
},
"overrides": [
// JSON linting
/*{
"files": ["*.json"],
"plugins": ["json-schema-validator"],
"extends": ["plugin:json-schema-validator/recommended"]
},*/
// TypeScript linting
{
"files": ["*.ts", "*.mts", "*.cts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint","import","@stylistic"],
"settings": {
"import/core-modules": [
"electron/main",
"electron/common",
"electron/renderer"
],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".mts", ".cts"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint","import"],
"settings": {
"import/core-modules": [
"electron/main",
"electron/common",
"electron/renderer"
],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".mts", ".cts"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.json"
}
}
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/strict",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:import/typescript"
],
"rules": {
/*** ESLint cosmetic rules ***/
"no-trailing-spaces": ["warn", {
"skipBlankLines": true,
"ignoreComments": true
}],
// Broken rules with TypeScript
"camelcase": "off",
"indent": "off",
"semi": "off",
"quotes": "off",
"no-use-before-define": "off",
"no-unused-vars": "off",
"no-unused-expressions": "off",

/*** ESLint built-in rules ***/
"valid-typeof": "error",
"guard-for-in": "error",
"no-await-in-loop": "error",
"no-unmodified-loop-condition": "error",
"eqeqeq": "error",
"no-constant-binary-expression": "error",
"no-eval": "error",
"no-restricted-imports": ["error", {
"name": "electron",
"message": "This module includes APIs for all process types, which could cause runtime error on misuse. Please use 'electron/common', 'electron/main' or 'electron/renderer' to explicitly declare intended process type instead."
}],
}
}
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/strict",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:import/typescript"
],
"rules": {
/*** ESLint built-in rules ***/
"valid-typeof": "error",
"guard-for-in": "error",
"no-await-in-loop": "error",
"no-unmodified-loop-condition": "error",
"eqeqeq": "error",
"no-constant-binary-expression": "error",
"no-eval": "error",
"no-restricted-imports": ["error", {
"name": "electron",
"message": "This module includes APIs for all process types, which could cause runtime error on misuse. Please use 'electron/common', 'electron/main' or 'electron/renderer' to explicitly declare intended process type instead."
}],
"no-empty": ["error", { "allowEmptyCatch": true }],

/*** TypeScript ESLint cosmetic rules ***/
"@typescript-eslint/member-delimiter-style": "warn",
"@typescript-eslint/indent": ["warn", 2, {
"SwitchCase": 1
}],
"@typescript-eslint/semi": "warn",
"@typescript-eslint/quotes": ["warn", "double", {"avoidEscape": true }],
"@typescript-eslint/no-use-before-define": "warn",
"@typescript-eslint/no-unused-expressions": "warn",
"@typescript-eslint/naming-convention": ["warn",{
"selector": "variableLike",
"format": ["camelCase"]
},{
"selector": "variable",
"modifiers": ["destructured"],
"format": ["camelCase","PascalCase"]
},{
"selector": "parameter",
"format": ["camelCase"],
"modifiers": ["unused"],
"leadingUnderscore": "require"
},{
"selector": "typeLike",
"format": ["PascalCase"]
},{
"selector": "typeAlias",
"format": ["camelCase","PascalCase"]
},{
"selector": "typeParameter",
"format": ["PascalCase"],
"custom": {
"regex": "^[A-Z]$",
"match": true
}
}],
/*** TypeScript ESLint plugin rules ***/
"@typescript-eslint/switch-exhaustiveness-check": "warn",
"@typescript-eslint/strict-boolean-expressions": ["error", {
"allowString": false,
"allowNumber": false
}],
"@typescript-eslint/no-confusing-void-expression": ["warn", {
"ignoreArrowShorthand": true
}],
"@typescript-eslint/consistent-type-assertions": ["error", {
"assertionStyle": "as",
"objectLiteralTypeAssertions": "never"
}],
"@typescript-eslint/no-meaningless-void-operator": ["error", {
"checkNever": true
}],
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-return": "error",
// Same as in TSC.
"@typescript-eslint/no-unused-vars": "error",
// Interfaces compile faster.
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
// RegExp.prototype.exec might run faster, according to TypeScript ESLint.
"@typescript-eslint/prefer-regexp-exec": "error",
/*** Stylistic rules ***/
"@stylistic/no-trailing-spaces": ["warn", {
"skipBlankLines": true,
"ignoreComments": true
}],
"@stylistic/member-delimiter-style": "warn",
"@stylistic/indent": ["warn", 2, {
"SwitchCase": 1
}],
"@stylistic/semi": "warn",
"@stylistic/quotes": ["warn", "double", {"avoidEscape": true }],

/*** Import plugin rules ***/
"import/no-unused-modules": ["error", {
"unusedExports": true
}],
"import/no-unresolved": ["error", {
"ignore": ["^(node:)?original-fs$"]
}]
/*** TypeScript ESLint cosmetic rules ***/
"@typescript-eslint/no-use-before-define": "warn",
"@typescript-eslint/no-unused-expressions": "warn",
"@typescript-eslint/naming-convention": ["warn",{
"selector": "variableLike",
"format": ["camelCase"]
},{
"selector": "variable",
"modifiers": ["destructured"],
"format": ["camelCase","PascalCase"]
},{
"selector": "parameter",
"format": ["camelCase"],
"modifiers": ["unused"],
"leadingUnderscore": "require"
},{
"selector": "typeLike",
"format": ["PascalCase"]
},{
"selector": "typeAlias",
"format": ["camelCase","PascalCase"]
},{
"selector": "typeParameter",
"format": ["PascalCase"],
"custom": {
"regex": "^[A-Z]$",
"match": true
}
}
]
}],

/*** TypeScript ESLint plugin rules ***/
"@typescript-eslint/switch-exhaustiveness-check": "warn",
"@typescript-eslint/strict-boolean-expressions": ["error", {
"allowString": false,
"allowNumber": false
}],
"@typescript-eslint/no-confusing-void-expression": ["warn", {
"ignoreArrowShorthand": true
}],
"@typescript-eslint/consistent-type-assertions": ["error", {
"assertionStyle": "as",
"objectLiteralTypeAssertions": "never"
}],
"@typescript-eslint/no-meaningless-void-operator": ["error", {
"checkNever": true
}],
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-return": "error",
// Same as in TSC.
"@typescript-eslint/no-unused-vars": "error",
// Interfaces compile faster.
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
// RegExp.prototype.exec might run faster, according to TypeScript ESLint.
"@typescript-eslint/prefer-regexp-exec": "error",

/*** Import plugin rules ***/
"import/no-unused-modules": ["error", {
"unusedExports": true
}],
"import/no-unresolved": ["error", {
"ignore": ["^(node:)?original-fs$"]
}]
}
}
Loading

0 comments on commit dfb18b3

Please sign in to comment.