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)!: change recommended config #729

Merged
merged 22 commits into from Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07a59d8
feat(eslint-plugin): change recommended config
bradzacher Jul 20, 2019
659115d
feat: disable base rules, prettier generated configs
bradzacher Jul 21, 2019
8d3cb2a
Merge branch 'master' into v2-update-recommended
bradzacher Jul 21, 2019
9b39860
Merge branch 'master' into v2-update-recommended
bradzacher Jul 25, 2019
52c1699
Merge branch 'master' into v2-update-recommended
bradzacher Jul 25, 2019
42d62f7
fix: lint errors
bradzacher Jul 25, 2019
df4b45c
Merge branch 'master' into v2-update-recommended
bradzacher Jul 25, 2019
d1ec431
Merge branch 'master' into v2-update-recommended
bradzacher Jul 28, 2019
c9ca0fe
chore: fix lint errors
bradzacher Jul 28, 2019
20761bb
Merge branch 'master' into v2-update-recommended
bradzacher Jul 29, 2019
22d2db7
chore: update yarn.lock
bradzacher Jul 29, 2019
ce7ecf1
Merge branch 'master' into v2-update-recommended
bradzacher Jul 29, 2019
a03c88f
feat: change defaults of no-this-alias
bradzacher Jul 29, 2019
bf4ae8a
fix: add generation for rules added in #595
bradzacher Jul 29, 2019
c3aef68
fix: fix the test because I'm a dummy
bradzacher Jul 30, 2019
953d20d
Merge branch 'master' into v2-update-recommended
bradzacher Jul 30, 2019
a031e18
chore: review fixes
bradzacher Jul 31, 2019
0c0cbc3
Merge branch 'master' into v2-update-recommended
bradzacher Aug 2, 2019
81b9d43
fix: correct defaults for no-inferrable-types
bradzacher Aug 8, 2019
a0404b8
docs: update no-inferrable-types docs
bradzacher Aug 8, 2019
aa1193e
fix: lint
bradzacher Aug 8, 2019
d56558b
Merge branch 'master' into v2-update-recommended
JamesHenry Aug 13, 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
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -25,7 +25,8 @@
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off"
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/unbound-method": "off"
},
"parserOptions": {
"sourceType": "module",
Expand Down
File renamed without changes.
36 changes: 18 additions & 18 deletions packages/eslint-plugin/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/eslint-plugin/package.json
Expand Up @@ -49,6 +49,7 @@
"devDependencies": {
"@types/json-schema": "^7.0.3",
"@types/marked": "^0.6.5",
"@types/prettier": "^1.18.0",
"chalk": "^2.4.2",
"marked": "^0.6.2"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/configs/all.json
Expand Up @@ -24,6 +24,7 @@
"@typescript-eslint/member-ordering": "error",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
Expand Down Expand Up @@ -62,6 +63,7 @@
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"require-await": "off",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
Expand Down
8 changes: 2 additions & 6 deletions packages/eslint-plugin/src/configs/base.json
@@ -1,9 +1,5 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
]
"parserOptions": { "sourceType": "module" },
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"plugins": ["@typescript-eslint"]
}
27 changes: 16 additions & 11 deletions packages/eslint-plugin/src/configs/recommended.json
@@ -1,38 +1,43 @@
{
"extends": "./configs/base.json",
"rules": {
"no-var": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"@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/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/explicit-member-accessibility": "error",
"indent": "off",
"@typescript-eslint/indent": "error",
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/member-delimiter-style": "error",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": "error",
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-parameter-properties": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/type-annotation-spacing": "error"
"@typescript-eslint/prefer-regexp-exec": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"require-await": "off",
"@typescript-eslint/require-await": "error",
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unbound-method": "error"
}
}
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -94,7 +94,8 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Requires using either `T[]` or `Array<T>` for arrays',
category: 'Stylistic Issues',
recommended: 'error',
// too opinionated to be recommended
recommended: false,
},
fixable: 'code',
messages: {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/await-thenable.ts
Expand Up @@ -9,7 +9,7 @@ export default util.createRule({
docs: {
description: 'Disallows awaiting a value that is not a Thenable',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
messages: {
await: 'Unexpected `await` of a non-Promise (non-"Thenable") value.',
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/ban-ts-ignore.ts
Expand Up @@ -7,7 +7,7 @@ export default util.createRule({
docs: {
description: 'Bans “// @ts-ignore” comments from being used',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
schema: [],
messages: {
Expand Down
9 changes: 6 additions & 3 deletions packages/eslint-plugin/src/rules/camelcase.ts
Expand Up @@ -37,15 +37,18 @@ export default util.createRule<Options, MessageIds>({
];

const properties = options.properties;
const allow = options.allow!;
const allow = options.allow!.map(r => ({
regexp: new RegExp(r),
name: r,
}));

/**
* Checks if a string contains an underscore and isn't all upper-case
* @param name The string to check.
*/
function isUnderscored(name: string): boolean {
// if there's an underscore, it might be A_CONSTANT, which is okay
return name.indexOf('_') > -1 && name !== name.toUpperCase();
return name.includes('_') && name !== name.toUpperCase();
}

/**
Expand All @@ -57,7 +60,7 @@ export default util.createRule<Options, MessageIds>({
function isAllowed(name: string): boolean {
return (
allow.findIndex(
entry => name === entry || name.match(new RegExp(entry)) !== null,
entry => name === entry.name || entry.regexp.test(name),
) !== -1
);
}
Expand Down
Expand Up @@ -9,6 +9,7 @@ export default util.createRule({
description:
'Consistent with type definition either `interface` or `type`',
category: 'Stylistic Issues',
// too opinionated to be recommended
recommended: false,
},
messages: {
Expand Down
Expand Up @@ -47,8 +47,8 @@ export default util.createRule<Options, MessageIds>({
defaultOptions: [
{
allowExpressions: false,
allowTypedFunctionExpressions: false,
allowHigherOrderFunctions: false,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
},
],
create(context, [options]) {
Expand Down
Expand Up @@ -33,8 +33,9 @@ export default util.createRule<Options, MessageIds>({
docs: {
description:
'Require explicit accessibility modifiers on class properties and methods',
category: 'Best Practices',
recommended: 'error',
category: 'Stylistic Issues',
// too opinionated to be recommended
recommended: false,
},
messages: {
missingAccessibility:
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/generic-type-naming.ts
Expand Up @@ -10,6 +10,7 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Enforces naming of generic type variables',
category: 'Stylistic Issues',
// too opinionated to be recommended
recommended: false,
},
messages: {
Expand Down
25 changes: 11 additions & 14 deletions packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts
Expand Up @@ -25,9 +25,8 @@ import { OffsetStorage } from './OffsetStorage';
import { TokenInfo } from './TokenInfo';
import { createRule, ExcludeKeys, RequireKeys } from '../../util';

function createGlobalLinebreakMatcher() {
return /\r\n|[\r\n\u2028\u2029]/gu;
}
const GLOBAL_LINEBREAK_REGEX = /\r\n|[\r\n\u2028\u2029]/gu;
const WHITESPACE_REGEX = /\s*$/u;

//------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -540,7 +539,7 @@ export default createRule<Options, MessageIds>({
while (
statement &&
((statement.type === AST_NODE_TYPES.UnaryExpression &&
['!', '~', '+', '-'].indexOf(statement.operator) > -1) ||
['!', '~', '+', '-'].includes(statement.operator)) ||
statement.type === AST_NODE_TYPES.AssignmentExpression ||
statement.type === AST_NODE_TYPES.LogicalExpression ||
statement.type === AST_NODE_TYPES.SequenceExpression ||
Expand All @@ -565,10 +564,8 @@ export default createRule<Options, MessageIds>({
* or the total number of linebreaks if the string is all whitespace.
*/
function countTrailingLinebreaks(str: string): number {
const trailingWhitespace = str.match(/\s*$/u)![0];
const linebreakMatches = trailingWhitespace.match(
createGlobalLinebreakMatcher(),
);
const trailingWhitespace = WHITESPACE_REGEX.exec(str)![0];
const linebreakMatches = GLOBAL_LINEBREAK_REGEX.exec(trailingWhitespace);

return linebreakMatches === null ? 0 : linebreakMatches.length;
}
Expand Down Expand Up @@ -722,7 +719,7 @@ export default createRule<Options, MessageIds>({
parameterParens.add(closingParen);
offsets.setDesiredOffset(
openingParen,
sourceCode.getTokenBefore(openingParen)!,
sourceCode.getTokenBefore(openingParen),
0,
);

Expand Down Expand Up @@ -900,7 +897,7 @@ export default createRule<Options, MessageIds>({

offsets.setDesiredOffsets(
[operator.range[0], node.range[1]],
sourceCode.getLastToken(node.left)!,
sourceCode.getLastToken(node.left),
1,
);
offsets.ignoreToken(operator);
Expand Down Expand Up @@ -958,7 +955,7 @@ export default createRule<Options, MessageIds>({
if (node.parent && !STATEMENT_LIST_PARENTS.has(node.parent.type)) {
offsets.setDesiredOffset(
sourceCode.getFirstToken(node)!,
sourceCode.getFirstToken(node.parent)!,
sourceCode.getFirstToken(node.parent),
0,
);
}
Expand Down Expand Up @@ -1088,7 +1085,7 @@ export default createRule<Options, MessageIds>({
// Indent everything after and including the `from` token in `export {foo, bar, baz} from 'qux'`
offsets.setDesiredOffsets(
[closingCurly.range[1], node.range[1]],
sourceCode.getFirstToken(node)!,
sourceCode.getFirstToken(node),
1,
);
}
Expand Down Expand Up @@ -1182,7 +1179,7 @@ export default createRule<Options, MessageIds>({

offsets.setDesiredOffsets(
[fromToken.range[0], end],
sourceCode.getFirstToken(node)!,
sourceCode.getFirstToken(node),
1,
);
}
Expand Down Expand Up @@ -1521,7 +1518,7 @@ export default createRule<Options, MessageIds>({
}
offsets.setDesiredOffsets(
node.name.range,
sourceCode.getFirstToken(node)!,
sourceCode.getFirstToken(node),
);
addElementListIndent(node.attributes, firstToken, closingToken, 1);
},
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/indent.ts
Expand Up @@ -89,7 +89,8 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Enforce consistent indentation',
category: 'Stylistic Issues',
recommended: 'error',
// too opinionated to be recommended
recommended: false,
},
fixable: 'whitespace',
schema: baseRule.meta.schema,
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/interface-name-prefix.ts
Expand Up @@ -10,6 +10,8 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Require that interface names be prefixed with `I`',
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
category: 'Stylistic Issues',
// this will always be recommended as there's no reason to use this convention
// https://github.com/typescript-eslint/typescript-eslint/issues/374
recommended: 'error',
},
messages: {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Expand Up @@ -26,7 +26,7 @@ const allMemberTypes = ['field', 'method', 'constructor'].reduce<string[]>(
if (type !== 'constructor') {
// There is no `static-constructor` or `instance-constructor
['static', 'instance'].forEach(scope => {
if (all.indexOf(`${scope}-${type}`) === -1) {
if (!all.includes(`${scope}-${type}`)) {
all.push(`${scope}-${type}`);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ export default util.createRule<Options, MessageIds>({
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'constructor';
case AST_NODE_TYPES.ClassProperty:
return node.value && functionExpressions.indexOf(node.value.type) > -1
return node.value && functionExpressions.includes(node.value.type)
? 'method'
: 'field';
case AST_NODE_TYPES.TSPropertySignature:
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-empty-function.ts
Expand Up @@ -15,7 +15,7 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Disallow empty functions',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
schema: baseRule.meta.schema,
messages: baseRule.meta.messages,
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/no-floating-promises.ts
Expand Up @@ -25,9 +25,9 @@ export default util.createRule({

return {
ExpressionStatement(node) {
const { expression } = parserServices.esTreeNodeToTSNodeMap.get(
node,
) as ts.ExpressionStatement;
const { expression } = parserServices.esTreeNodeToTSNodeMap.get<
ts.ExpressionStatement
>(node);

if (isUnhandledPromise(checker, expression)) {
context.report({
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-for-in-array.ts
Expand Up @@ -7,7 +7,7 @@ export default util.createRule({
docs: {
description: 'Disallow iterating over an array with a for-in loop',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
messages: {
forInViolation:
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-misused-new.ts
Expand Up @@ -16,7 +16,7 @@ export default util.createRule({
schema: [],
messages: {
errorMessageInterface: 'Interfaces cannot be constructed, only classes.',
errorMessageClass: 'Class cannon have method named `new`.',
errorMessageClass: 'Class cannot have method named `new`.',
},
},
defaultOptions: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-misused-promises.ts
Expand Up @@ -17,7 +17,7 @@ export default util.createRule<Options, 'conditional' | 'voidReturn'>({
docs: {
description: 'Avoid using promises in places not designed to handle them',
category: 'Best Practices',
recommended: false,
recommended: 'error',
},
messages: {
voidReturn:
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-non-null-assertion.ts
Expand Up @@ -8,7 +8,7 @@ export default util.createRule({
description:
'Disallows non-null assertions using the `!` postfix operator',
category: 'Stylistic Issues',
recommended: 'error',
recommended: 'warn',
},
messages: {
noNonNull: 'Forbidden non-null assertion.',
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-plugin/src/rules/no-parameter-properties.ts
Expand Up @@ -27,7 +27,8 @@ export default util.createRule<Options, MessageIds>({
description:
'Disallow the use of parameter properties in class constructors',
category: 'Stylistic Issues',
recommended: 'error',
// too opinionated to be recommended
recommended: false,
},
messages: {
noParamProp:
Expand Down Expand Up @@ -84,7 +85,7 @@ export default util.createRule<Options, MessageIds>({
TSParameterProperty(node) {
const modifiers = getModifiers(node);

if (allows.indexOf(modifiers) === -1) {
if (!allows.includes(modifiers)) {
// HAS to be an identifier or assignment or TSC will throw
if (
node.parameter.type !== AST_NODE_TYPES.Identifier &&
Expand Down