Skip to content

Commit

Permalink
build(devs-dep): simplify eslint config (#2403)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Feb 25, 2021
1 parent 77871b8 commit 8615306
Show file tree
Hide file tree
Showing 40 changed files with 250 additions and 328 deletions.
312 changes: 60 additions & 252 deletions .eslintrc.js
Expand Up @@ -4,266 +4,74 @@ module.exports = {
es6: true,
'jest/globals': true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:jest/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
ecmaVersion: 2020,
sourceType: 'module',
impliedStrict: true,
ecmaFeatures: {
jsx: true,
},
},
plugins: ['@typescript-eslint', 'import', 'jest', 'jsdoc'],
rules: {
'arrow-body-style': 'warn',
'arrow-parens': ['off', 'always'],
'brace-style': ['off', 'off'],
camelcase: 'warn',
'class-methods-use-this': 'warn',
'comma-dangle': 'off',
complexity: 'off',
'constructor-super': 'error',
curly: ['warn', 'multi-line'],
'default-case': 'error',
'dot-notation': 'error',
'eol-last': 'off',
eqeqeq: ['error', 'smart'],
'for-direction': ['error'],
'getter-return': 'warn',
'guard-for-in': 'error',
'id-match': 'error',
'import/order': [
'error',
{
'alphabetize': {
'order': 'asc',
'caseInsensitive': true,
},
// this is the default order except for added `internal` in the middle
'groups': [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
'newlines-between': 'always',
}
],
'jest/valid-title': 'off',
'jest/no-conditional-expect': 'off',
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
'jsdoc/newline-after-description': 'warn',
'linebreak-style': 'off',
'max-classes-per-file': 'off',
'max-len': 'off',
'new-parens': 'off',
'newline-per-chained-call': 'off',
'no-bitwise': 'off',
'no-caller': 'error',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-console': 'error',
'no-async-promise-executor': ['error'],
'no-case-declarations': ['error'],
'no-class-assign': ['error'],
'no-compare-neg-zero': ['error'],
'no-cond-assign': 'error',
'no-const-assign': ['error'],
'no-constant-condition': ['warn'],
'no-control-regex': ['warn'],
'no-debugger': 'error',
'no-delete-var': ['error'],
'no-dupe-args': ['error'],
'no-dupe-class-members': 'warn',
'no-dupe-keys': ['error'],
'no-duplicate-case': ['error'],
'no-empty': [
'error',
{
allowEmptyCatch: true,
},
],
'no-empty-character-class': ['error'],
'no-empty-pattern': ['error'],
'no-ex-assign': ['error'],
'no-extra-boolean-cast': ['error'],
'no-extra-semi': 'off',
'no-fallthrough': 'off',
'no-func-assign': ['error'],
'no-global-assign': ['error'],
'no-inner-declarations': ['error'],
'no-invalid-this': 'off',
'no-invalid-regexp': ['error'],
'no-irregular-whitespace': 'off',
'no-misleading-character-class': ['error'],
'no-mixed-spaces-and-tabs': ['error'],
'no-multiple-empty-lines': 'off',
'no-new-symbol': ['error'],
'no-new-wrappers': 'error',
'no-obj-calls': ['error'],
'no-octal': ['error'],
'no-prototype-builtins': ['error'],
'no-redeclare': 'warn',
'no-regex-spaces': ['error'],
'no-return-await': 'error',
'no-self-assign': ['error'],
'no-shadow': [
'off',
{
hoist: 'all',
},
],
'no-shadow-restricted-names': ['error'],
'no-sparse-arrays': ['error'],
'no-template-curly-in-string': 'error',
'no-this-before-super': ['error'],
'no-throw-literal': 'error',
'no-trailing-spaces': 'off',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-unused-expressions': [
'error',
{ allowTernary: true },
],
'no-undef': ['error'],
'no-unexpected-multiline': ['error'],
'no-unreachable': ['error'],
'no-unsafe-finally': 'error',
'no-unsafe-negation': ['error'],
'no-unused-labels': 'error',
'no-unused-vars': 'off', // let typescript-eslint handle this
'no-useless-catch': ['error'],
'no-useless-escape': 'warn',
'no-var': 'error',
'no-with': ['error'],
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'padding-line-between-statements': [
"error",
{ blankLine: "always", prev: "*", next: "return" }
],
'prefer-const': 'error',
'prefer-object-spread': 'error',
'prefer-template': 'error',
'prettier/prettier': 'error',
'quote-props': 'off',
radix: 'error',
'require-yield': ['error'],
'space-before-function-paren': 'off',
'space-in-parens': ['off', 'never'],
'spaced-comment': [
'warn',
'always',
{
markers: ['/'],
},
],
'use-isnan': 'error',
'valid-typeof': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': [
'warn',
{
default: 'array',
},
],
'@typescript-eslint/ban-types': [
'error',
{
types: {
Object: {
message: 'Avoid using the `Object` type. Did you mean `object`?',
},
Function: {
message: 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.',
},
Boolean: {
message: 'Avoid using the `Boolean` type. Did you mean `boolean`?',
},
Number: {
message: 'Avoid using the `Number` type. Did you mean `number`?',
},
String: {
message: 'Avoid using the `String` type. Did you mean `string`?',
},
Symbol: {
message: 'Avoid using the `Symbol` type. Did you mean `symbol`?',
},
},
overrides: [
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
impliedStrict: true,
createDefaultProgram: true,
},
],
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'no-public',
},
],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'none',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }],
'@typescript-eslint/no-empty-function': ['error', { 'allow': ['arrowFunctions']}],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'warn',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-includes': 'warn',
'@typescript-eslint/prefer-regexp-exec': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/triple-slash-reference': [
'error',
{
path: 'always',
types: 'prefer-import',
lib: 'always',
plugins: ['eslint-plugin-prefer-arrow', 'import', 'jsdoc'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
'plugin:import/typescript',
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/array-type': [
'error',
{
'default': 'array-simple',
}
],
'@typescript-eslint/comma-spacing': 'error',
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'jest/valid-title': 'off',
'import/order': [
'error',
{
'alphabetize': {
'order': 'asc',
'caseInsensitive': true,
},
// this is the default order except for added `internal` in the middle
'groups': [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
'newlines-between': 'always',
}
],
'object-shorthand': 'error',
'padding-line-between-statements': [
'error',
{ 'blankLine': 'always', 'prev': '*', 'next': 'return' },
],
'prefer-object-spread': 'error',
},
],
'@typescript-eslint/type-annotation-spacing': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'error',
}
],
rules: {
'comma-spacing': 'off',
'no-redeclare': 'off',
'no-shadow': 'off',
'quotes': 'off',
},
settings: {},
}
2 changes: 2 additions & 0 deletions e2e/__helpers__/test-case/run-descriptor.ts
Expand Up @@ -8,6 +8,7 @@ import type { RunTestOptions, RunWithTemplateIteratorContext, RunWithTemplatesIt

export default class RunDescriptor {
protected _options: RunTestOptions
// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected _sourcePackageJson: any

constructor(readonly name: string, options: RunTestOptions = {}) {
Expand All @@ -18,6 +19,7 @@ export default class RunDescriptor {
return join(Paths.e2eSourceDir, this.name)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
get sourcePackageJson(): any {
try {
return this._sourcePackageJson || (this._sourcePackageJson = require(join(this.sourceDir, 'package.json')))
Expand Down
4 changes: 3 additions & 1 deletion e2e/__helpers__/test-case/run-result.ts
Expand Up @@ -89,7 +89,8 @@ export default class RunResult {
if (!this.context.ioDir) {
throw new Error('IO not written for test, you must configure the test with `writeIo: true`.')
}
let io: any = { in: ['', '', {}, {}], out: '' }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let io: Record<string, any> = { in: ['', '', {}, {}], out: '' }
try {
io = require(`${this.context.ioDir}/${relFilePath}.json`)
} catch (err) {
Expand Down Expand Up @@ -127,6 +128,7 @@ export default class RunResult {
}

return map
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.sort((a, b) => ((b.from as any).length || Infinity) - ((a.from as any).length || Infinity))
.reduce((str, { from, to }) => str.replace(typeof from === 'string' ? new RegExp(`${escapeRegex(from)}`, 'g') : from, to), str)
}
Expand Down

0 comments on commit 8615306

Please sign in to comment.