Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): add config all.json #313

Merged
merged 30 commits into from May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b6d7590
feat(eslint-plugin): add config all.json
ldrick Feb 24, 2019
8de8ddc
Merge branch 'master' into provide-all-config
ldrick Feb 25, 2019
3cb4567
fix: no new rules for recommended.json and extract base.json
ldrick Feb 27, 2019
886b765
fix: export base.json and all.json
ldrick Feb 28, 2019
c51d434
fix: path to base.json
ldrick Feb 28, 2019
c0eec0e
fix: regenerate configs with fixed path
ldrick Feb 28, 2019
e9a012c
feat(eslint-plugin): provide index.ts to collect rules
ldrick Mar 2, 2019
fdd01d9
test: add tests for ./src/rules/index.ts and ./src/.configs/all.json
ldrick Mar 2, 2019
507c14a
fix: test for Node.js 6
ldrick Mar 2, 2019
876e70c
fix: remove left overs
ldrick Mar 2, 2019
c951296
Merge branch 'master' into provide-all-config
ldrick Mar 2, 2019
883fa47
test: improve coverage
ldrick Mar 3, 2019
ec021d7
feat(eslint-plugin): disable eslints "no-useless-constructor" rule
ldrick Mar 5, 2019
3d9205a
Merge branch 'master' into provide-all-config
ldrick Mar 7, 2019
863654e
feat(eslint-plugin): add base config to generated configs
ldrick Mar 7, 2019
1ed1044
Merge branch 'master' into provide-all-config
ldrick Mar 10, 2019
f8bc247
Merge branch 'master' into provide-all-config
ldrick Mar 15, 2019
6b7b435
fix: remove recommendation from docs for rules not in config
ldrick Mar 15, 2019
5b65090
chore: merge master
ldrick Mar 21, 2019
673b82e
Merge remote-tracking branch 'upstream/master' into provide-all-config
ldrick Apr 26, 2019
66944f8
feat(eslint-plugin): set rules in all.json to 'error'
ldrick Apr 26, 2019
d91badc
Merge branch 'master' into provide-all-config
ldrick Apr 30, 2019
8a947ea
Merge remote-tracking branch 'upstream/master' into provide-all-config
ldrick May 3, 2019
b5cb999
Merge remote-tracking branch 'upstream/master' into provide-all-config
ldrick May 6, 2019
4f28f41
Merge remote-tracking branch 'upstream/master' into provide-all-config
ldrick May 10, 2019
83562a8
fix: for manual provided config
ldrick May 10, 2019
0c01c4a
Merge remote-tracking branch 'upstream/master' into provide-all-config
ldrick May 13, 2019
846c74b
fix: remove of unbound-method as recommended in docs again
ldrick May 13, 2019
aea2fd6
Merge remote-tracking branch 'upstream/master' into provide-all-config
ldrick May 13, 2019
ca6eb21
fix: all reviewed things and added deprecated filter
ldrick May 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Expand Up @@ -28,7 +28,7 @@
"docs": "eslint-docs",
"docs:check": "eslint-docs check",
"test": "jest --coverage",
"recommended:update": "ts-node tools/update-recommended.ts",
"create:config": "ts-node --files tools/create-config.ts",
"prebuild": "npm run clean",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/",
Expand Down
57 changes: 57 additions & 0 deletions packages/eslint-plugin/src/configs/all.json
@@ -0,0 +1,57 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
ldrick marked this conversation as resolved.
Show resolved Hide resolved
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "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": "warn",
"@typescript-eslint/explicit-member-accessibility": "error",
"@typescript-eslint/generic-type-naming": "warn",
"indent": "off",
"@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/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": "warn",
"@typescript-eslint/no-extraneous-class": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"@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": "error",
"@typescript-eslint/no-this-alias": "warn",
"@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",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-regexp-exec": "warn",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "warn",
"@typescript-eslint/restrict-plus-operands": "warn",
"@typescript-eslint/type-annotation-spacing": "error"
}
}
3 changes: 3 additions & 0 deletions packages/eslint-plugin/src/configs/recommended.json
Expand Up @@ -7,6 +7,7 @@
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"@typescript-eslint/ban-types": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
Expand All @@ -28,13 +29,15 @@
"@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-triple-slash-reference": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/promise-function-async": "error",
ldrick marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/type-annotation-spacing": "error"
}
}
102 changes: 102 additions & 0 deletions packages/eslint-plugin/tools/create-config.ts
@@ -0,0 +1,102 @@
/* eslint-disable no-console */

import path from 'path';
import fs from 'fs';
import requireIndex from 'requireindex';

const MAX_RULE_NAME_LENGTH = 33 + 'typescript-eslint/'.length;
const RULE_NAME_PREFIX = '@typescript-eslint';

const all = Object.entries(
requireIndex(path.resolve(__dirname, '../dist/rules')),
);

const baseConfig = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
};

const bannedRules = new Set([
'camelcase',
'indent',
'no-array-constructor',
'no-unused-vars',
]);

/**
* Helper function reduces records to key - value pairs.
* @param config
* @param entry
*/
const reducer = (
config: Record<string, string>,
entry: Record<string, any>,
): Record<string, string> => {
const key = entry[0];
const value = entry[1];
const ruleName = `${RULE_NAME_PREFIX}/${key}`;
const setting = value.default.meta.docs.recommended;
const usedSetting = !setting ? 'warn' : setting;

// having this here is just for output niceness (the keys will be ordered)
if (bannedRules.has(key)) {
console.log(key.padEnd(MAX_RULE_NAME_LENGTH), '= off');
config[key] = 'off';
}
console.log(ruleName.padEnd(MAX_RULE_NAME_LENGTH), '=', usedSetting);
config[ruleName] = usedSetting;

return config;
};

/**
* Helper function to check for invalid recommended setting.
*/
function checkValidSettings(): boolean {
const validSettings = ['error', 'warn', false];
let result = true;

all.forEach(entry => {
const key = entry[0];
const value = entry[1];
const setting = value.default.meta.docs.recommended;

if (!validSettings.includes(setting)) {
console.error(`ERR! Invalid level for rule ${key}: "${setting}"`);
result = false;
}
});

return result;
}

/**
* Helper function generates configuration.
*/
function generate(rules: Record<string, string>, filePath: string): void {
const config = Object.assign({}, baseConfig, { rules });

fs.writeFileSync(filePath, `${JSON.stringify(config, null, 2)}\n`);
}

if (checkValidSettings()) {
console.log('------------------------- all.json -------------------------');
generate(
all.reduce(reducer, {}),
path.resolve(__dirname, '../src/configs/all.json'),
);

console.log('--------------------- recommended.json ---------------------');
const recommendedSettings = ['error', 'warn'];
generate(
all
.filter(entry =>
recommendedSettings.includes(entry[1].default.meta.docs.recommended),
)
.reduce(reducer, {}),
path.resolve(__dirname, '../src/configs/recommended.json'),
);
}
ldrick marked this conversation as resolved.
Show resolved Hide resolved
68 changes: 0 additions & 68 deletions packages/eslint-plugin/tools/update-recommended.ts

This file was deleted.