Skip to content

Commit

Permalink
feat(eslint-plugin): set rules in all.json to 'error'
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrick committed Apr 26, 2019
1 parent 673b82e commit 66944f8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
56 changes: 28 additions & 28 deletions packages/eslint-plugin/src/configs/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "warn",
"@typescript-eslint/ban-ts-ignore": "warn",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/explicit-member-accessibility": "error",
"@typescript-eslint/func-call-spacing": "warn",
"@typescript-eslint/generic-type-naming": "warn",
"@typescript-eslint/func-call-spacing": "error",
"@typescript-eslint/generic-type-naming": "error",
"@typescript-eslint/indent": "error",
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/member-delimiter-style": "error",
"@typescript-eslint/member-naming": "warn",
"@typescript-eslint/member-ordering": "warn",
"@typescript-eslint/member-naming": "error",
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-angle-bracket-type-assertion": "error",
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-extra-parens": "warn",
"@typescript-eslint/no-extraneous-class": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"@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-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": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-triple-slash-reference": "error",
"@typescript-eslint/no-type-alias": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "warn",
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-type-alias": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "warn",
"@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-string-starts-ends-with": "warn",
"@typescript-eslint/promise-function-async": "warn",
"@typescript-eslint/require-array-sort-compare": "warn",
"@typescript-eslint/restrict-plus-operands": "warn",
"@typescript-eslint/semi": "warn",
"@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": "warn",
"@typescript-eslint/unified-signatures": "warn"
"@typescript-eslint/unbound-method": "error",
"@typescript-eslint/unified-signatures": "error"
}
}
4 changes: 2 additions & 2 deletions packages/eslint-plugin/tests/configs/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('all.json config', () => {
);
});

it('has all rules enabled either with "warn" or "error"', () => {
expect(['warn', 'error']).toEqual(expect.arrayContaining(configRuleValues));
it('has all rules enabled with "error"', () => {
expect(['error']).toEqual(expect.arrayContaining(configRuleValues));
});
});
18 changes: 14 additions & 4 deletions packages/eslint-plugin/tools/generate-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Linter } from 'eslint';

const RULE_NAME_PREFIX = '@typescript-eslint/';
const MAX_RULE_NAME_LENGTH = 32 + RULE_NAME_PREFIX.length;
const DEFAULT_RULE_SETTING = 'warn';

const ruleEntries = Object.entries(rules);

Expand All @@ -28,12 +29,18 @@ interface LinterConfig extends Linter.Config {
const reducer = <TMessageIds extends string>(
config: LinterConfigRules,
entry: [string, RuleModule<TMessageIds, any, any>],
setting?: 'error' | 'warn',
) => {
const key = entry[0];
const value = entry[1];
const ruleName = `${RULE_NAME_PREFIX}${key}`;
const setting = value.meta.docs.recommended;
const usedSetting = !setting ? 'warn' : setting;

const recommendation = value.meta.docs.recommended;
const usedSetting = setting
? setting
: !recommendation
? DEFAULT_RULE_SETTING
: recommendation;

console.log(ruleName.padEnd(MAX_RULE_NAME_LENGTH), '=', usedSetting);
config[ruleName] = usedSetting;
Expand Down Expand Up @@ -67,7 +74,10 @@ writeConfig(baseConfig, path.resolve(__dirname, '../src/configs/base.json'));
console.log('------------------------- all.json -------------------------');
const allConfig: LinterConfig = {
extends: './configs/base.json',
rules: ruleEntries.reduce(reducer, {}) as LinterConfigRules,
rules: ruleEntries.reduce(
(config, entry) => reducer(config, entry, 'error'),
{},
) as LinterConfigRules,
};
writeConfig(allConfig, path.resolve(__dirname, '../src/configs/all.json'));

Expand All @@ -76,7 +86,7 @@ const recommendedConfig: LinterConfig = {
extends: './configs/base.json',
rules: ruleEntries
.filter(entry => !!entry[1].meta.docs.recommended)
.reduce(reducer, {}) as LinterConfigRules,
.reduce((config, entry) => reducer(config, entry), {}) as LinterConfigRules,
};
writeConfig(
recommendedConfig,
Expand Down

0 comments on commit 66944f8

Please sign in to comment.