Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(eslint-plugin): add config all.json (#313)
- Loading branch information
1 parent
8c8497c
commit 67537b8
Showing
19 changed files
with
389 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"extends": "./configs/base.json", | ||
"rules": { | ||
"@typescript-eslint/adjacent-overload-signatures": "error", | ||
"@typescript-eslint/array-type": "error", | ||
"@typescript-eslint/await-thenable": "error", | ||
"@typescript-eslint/ban-ts-ignore": "error", | ||
"@typescript-eslint/ban-types": "error", | ||
"camelcase": "off", | ||
"@typescript-eslint/camelcase": "error", | ||
"@typescript-eslint/class-name-casing": "error", | ||
"@typescript-eslint/explicit-function-return-type": "error", | ||
"@typescript-eslint/explicit-member-accessibility": "error", | ||
"@typescript-eslint/func-call-spacing": "error", | ||
"@typescript-eslint/generic-type-naming": "error", | ||
"indent": "off", | ||
"@typescript-eslint/indent": "error", | ||
"@typescript-eslint/interface-name-prefix": "error", | ||
"@typescript-eslint/member-delimiter-style": "error", | ||
"@typescript-eslint/member-naming": "error", | ||
"@typescript-eslint/member-ordering": "error", | ||
"@typescript-eslint/no-angle-bracket-type-assertion": "error", | ||
"no-array-constructor": "off", | ||
"@typescript-eslint/no-array-constructor": "error", | ||
"@typescript-eslint/no-empty-interface": "error", | ||
"@typescript-eslint/no-explicit-any": "error", | ||
"@typescript-eslint/no-extra-parens": "error", | ||
"@typescript-eslint/no-extraneous-class": "error", | ||
"@typescript-eslint/no-for-in-array": "error", | ||
"@typescript-eslint/no-inferrable-types": "error", | ||
"@typescript-eslint/no-magic-numbers": "error", | ||
"@typescript-eslint/no-misused-new": "error", | ||
"@typescript-eslint/no-namespace": "error", | ||
"@typescript-eslint/no-non-null-assertion": "error", | ||
"@typescript-eslint/no-object-literal-type-assertion": "error", | ||
"@typescript-eslint/no-parameter-properties": "error", | ||
"@typescript-eslint/no-require-imports": "error", | ||
"@typescript-eslint/no-this-alias": "error", | ||
"@typescript-eslint/no-triple-slash-reference": "error", | ||
"@typescript-eslint/no-type-alias": "error", | ||
"@typescript-eslint/no-unnecessary-qualifier": "error", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "error", | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"@typescript-eslint/no-use-before-define": "error", | ||
"no-useless-constructor": "off", | ||
"@typescript-eslint/no-useless-constructor": "error", | ||
"@typescript-eslint/no-var-requires": "error", | ||
"@typescript-eslint/prefer-for-of": "error", | ||
"@typescript-eslint/prefer-function-type": "error", | ||
"@typescript-eslint/prefer-includes": "error", | ||
"@typescript-eslint/prefer-interface": "error", | ||
"@typescript-eslint/prefer-namespace-keyword": "error", | ||
"@typescript-eslint/prefer-regexp-exec": "error", | ||
"@typescript-eslint/prefer-string-starts-ends-with": "error", | ||
"@typescript-eslint/promise-function-async": "error", | ||
"@typescript-eslint/require-array-sort-compare": "error", | ||
"@typescript-eslint/restrict-plus-operands": "error", | ||
"@typescript-eslint/semi": "error", | ||
"@typescript-eslint/type-annotation-spacing": "error", | ||
"@typescript-eslint/unbound-method": "error", | ||
"@typescript-eslint/unified-signatures": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["@typescript-eslint"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import adjacentOverloadSignatures from './adjacent-overload-signatures'; | ||
import arrayType from './array-type'; | ||
import awaitThenable from './await-thenable'; | ||
import banTsIgnore from './ban-ts-ignore'; | ||
import banTypes from './ban-types'; | ||
import camelcase from './camelcase'; | ||
import classNameCasing from './class-name-casing'; | ||
import explicitFunctionReturnType from './explicit-function-return-type'; | ||
import explicitMemberAccessibility from './explicit-member-accessibility'; | ||
import funcCallSpacing from './func-call-spacing'; | ||
import genericTypeNaming from './generic-type-naming'; | ||
import indent from './indent'; | ||
import interfaceNamePrefix from './interface-name-prefix'; | ||
import memberDelimiterStyle from './member-delimiter-style'; | ||
import memberNaming from './member-naming'; | ||
import memberOrdering from './member-ordering'; | ||
import noAngleBracketTypeAssertion from './no-angle-bracket-type-assertion'; | ||
import noArrayConstructor from './no-array-constructor'; | ||
import noEmptyInterface from './no-empty-interface'; | ||
import noExplicitAny from './no-explicit-any'; | ||
import noExtraParens from './no-extra-parens'; | ||
import noExtraneousClass from './no-extraneous-class'; | ||
import noForInArray from './no-for-in-array'; | ||
import noInferrableTypes from './no-inferrable-types'; | ||
import noMagicNumbers from './no-magic-numbers'; | ||
import noMisusedNew from './no-misused-new'; | ||
import noNamespace from './no-namespace'; | ||
import noNonNullAssertion from './no-non-null-assertion'; | ||
import noObjectLiteralTypeAssertion from './no-object-literal-type-assertion'; | ||
import noParameterProperties from './no-parameter-properties'; | ||
import noRequireImports from './no-require-imports'; | ||
import noThisAlias from './no-this-alias'; | ||
import noTripleSlashReference from './no-triple-slash-reference'; | ||
import noTypeAlias from './no-type-alias'; | ||
import noUnnecessaryQualifier from './no-unnecessary-qualifier'; | ||
import noUnnecessaryTypeAssertion from './no-unnecessary-type-assertion'; | ||
import noUnusedVars from './no-unused-vars'; | ||
import noUseBeforeDefine from './no-use-before-define'; | ||
import noUselessConstructor from './no-useless-constructor'; | ||
import noVarRequires from './no-var-requires'; | ||
import preferForOf from './prefer-for-of'; | ||
import preferFunctionType from './prefer-function-type'; | ||
import preferIncludes from './prefer-includes'; | ||
import preferInterface from './prefer-interface'; | ||
import preferNamespaceKeyword from './prefer-namespace-keyword'; | ||
import preferRegexpExec from './prefer-regexp-exec'; | ||
import preferStringStartsEndsWith from './prefer-string-starts-ends-with'; | ||
import promiseFunctionAsync from './promise-function-async'; | ||
import requireArraySortCompare from './require-array-sort-compare'; | ||
import restrictPlusOperands from './restrict-plus-operands'; | ||
import semi from './semi'; | ||
import typeAnnotationSpacing from './type-annotation-spacing'; | ||
import unboundMethod from './unbound-method'; | ||
import unifiedSignatures from './unified-signatures'; | ||
|
||
export default { | ||
'adjacent-overload-signatures': adjacentOverloadSignatures, | ||
'array-type': arrayType, | ||
'await-thenable': awaitThenable, | ||
'ban-ts-ignore': banTsIgnore, | ||
'ban-types': banTypes, | ||
camelcase: camelcase, | ||
'class-name-casing': classNameCasing, | ||
'explicit-function-return-type': explicitFunctionReturnType, | ||
'explicit-member-accessibility': explicitMemberAccessibility, | ||
'func-call-spacing': funcCallSpacing, | ||
'generic-type-naming': genericTypeNaming, | ||
indent: indent, | ||
'interface-name-prefix': interfaceNamePrefix, | ||
'member-delimiter-style': memberDelimiterStyle, | ||
'member-naming': memberNaming, | ||
'member-ordering': memberOrdering, | ||
'no-angle-bracket-type-assertion': noAngleBracketTypeAssertion, | ||
'no-array-constructor': noArrayConstructor, | ||
'no-empty-interface': noEmptyInterface, | ||
'no-explicit-any': noExplicitAny, | ||
'no-extra-parens': noExtraParens, | ||
'no-extraneous-class': noExtraneousClass, | ||
'no-for-in-array': noForInArray, | ||
'no-inferrable-types': noInferrableTypes, | ||
'no-magic-numbers': noMagicNumbers, | ||
'no-misused-new': noMisusedNew, | ||
'no-namespace': noNamespace, | ||
'no-non-null-assertion': noNonNullAssertion, | ||
'no-object-literal-type-assertion': noObjectLiteralTypeAssertion, | ||
'no-parameter-properties': noParameterProperties, | ||
'no-require-imports': noRequireImports, | ||
'no-this-alias': noThisAlias, | ||
'no-triple-slash-reference': noTripleSlashReference, | ||
'no-type-alias': noTypeAlias, | ||
'no-unnecessary-qualifier': noUnnecessaryQualifier, | ||
'no-unnecessary-type-assertion': noUnnecessaryTypeAssertion, | ||
'no-unused-vars': noUnusedVars, | ||
'no-use-before-define': noUseBeforeDefine, | ||
'no-useless-constructor': noUselessConstructor, | ||
'no-var-requires': noVarRequires, | ||
'prefer-for-of': preferForOf, | ||
'prefer-function-type': preferFunctionType, | ||
'prefer-includes': preferIncludes, | ||
'prefer-interface': preferInterface, | ||
'prefer-namespace-keyword': preferNamespaceKeyword, | ||
'prefer-regexp-exec': preferRegexpExec, | ||
'prefer-string-starts-ends-with': preferStringStartsEndsWith, | ||
'promise-function-async': promiseFunctionAsync, | ||
'require-array-sort-compare': requireArraySortCompare, | ||
'restrict-plus-operands': restrictPlusOperands, | ||
semi: semi, | ||
'type-annotation-spacing': typeAnnotationSpacing, | ||
'unbound-method': unboundMethod, | ||
'unified-signatures': unifiedSignatures, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import rules from '../../src/rules'; | ||
import allConfig from '../../src/configs/all.json'; | ||
import { TSESLint } from '@typescript-eslint/experimental-utils'; | ||
|
||
interface IndexRules { | ||
[name: string]: TSESLint.RuleModule<string, any, any>; | ||
} | ||
interface JsonRules { | ||
[name: string]: string; | ||
} | ||
|
||
describe('all.json config', () => { | ||
const RULE_NAME_PREFIX = '@typescript-eslint/'; | ||
|
||
const typedRules: IndexRules = rules; | ||
const notDeprecatedRuleNames = Object.keys(typedRules).reduce<string[]>( | ||
(collection, name) => { | ||
if (!typedRules[name].meta.deprecated) { | ||
collection.push(`${RULE_NAME_PREFIX}${name}`); | ||
} | ||
return collection; | ||
}, | ||
[], | ||
); | ||
|
||
// with end of Node.js 6 support, we can use Object.entries(allConfig.rules) here | ||
const configRules: JsonRules = allConfig.rules; | ||
const typescriptEslintConfigRules = Object.keys(configRules).filter(name => | ||
name.startsWith(RULE_NAME_PREFIX), | ||
); | ||
const typescriptEslintConfigRuleValues = typescriptEslintConfigRules.map( | ||
name => configRules[name], | ||
); | ||
|
||
it('contains all @typescript-eslint/eslint-plugin rule modules, except the deprecated ones', () => { | ||
expect(notDeprecatedRuleNames).toEqual( | ||
expect.arrayContaining(typescriptEslintConfigRules), | ||
); | ||
}); | ||
|
||
it('has all containing @typescript-eslint/eslint-plugin rules enabled with "error"', () => { | ||
expect(['error']).toEqual( | ||
expect.arrayContaining(typescriptEslintConfigRuleValues), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import eslintPlugin from '../src'; | ||
import rules from '../src/rules'; | ||
|
||
describe('eslint-plugin ("./src/index.ts")', () => { | ||
const ruleKeys = Object.keys(rules); | ||
const eslintPluginRuleKeys = Object.keys(eslintPlugin.rules); | ||
|
||
const configs = fs | ||
.readdirSync('./src/configs') | ||
.filter(file => ['.json', '.ts'].includes(path.extname(file).toLowerCase())) | ||
.map(file => path.basename(file, path.extname(file))); | ||
const eslintPluginConfigKeys = Object.keys(eslintPlugin.configs); | ||
|
||
it('exports all available rules', () => { | ||
expect(ruleKeys).toEqual(expect.arrayContaining(eslintPluginRuleKeys)); | ||
}); | ||
|
||
it('exports all available configs', () => { | ||
expect(configs).toEqual(expect.arrayContaining(eslintPluginConfigKeys)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs from 'fs'; | ||
|
||
import rules from '../../src/rules'; | ||
|
||
describe('./src/rules/index.ts', () => { | ||
const ruleNames = Object.keys(rules).map(name => `${name}.ts`); | ||
const files = fs | ||
.readdirSync('./src/rules') | ||
.filter(file => file !== 'index.ts' && file.endsWith('.ts')); | ||
|
||
it('imports all available rule modules', () => { | ||
expect(ruleNames).toEqual(expect.arrayContaining(files)); | ||
}); | ||
}); |
Oops, something went wrong.