Skip to content

feat: upgrade to ESLint v7 #2022

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

Merged
merged 13 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = {
],
parserOptions: {
sourceType: 'module',
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
project: [
'./tsconfig.eslint.json',
'./tests/integration/utils/jsconfig.json',
'./packages/*/tsconfig.json',
],
tsconfigRootDir: __dirname,
warnOnUnsupportedTypeScriptVersion: false,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"all-contributors-cli": "^6.14.2",
"cspell": "^4.0.61",
"cz-conventional-changelog": "^3.2.0",
"eslint": "^6.7.0",
"eslint": "^7.0.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-eslint-plugin": "^2.2.1",
"eslint-plugin-import": "^2.20.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default createRule({
suggest: [
{
messageId: 'suggestedFix',
data: banned,
fix(fixer): TSESLint.RuleFix | null {
if (banned.fixWith == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,27 @@ ruleTester.run({
],
},
],
});
`,
output: `
ruleTester.run({
valid: [],
invalid: [
{
code: 'const x = 1;',
errors: [
{
messageId: 'foo',
suggestions: [
{
messageId: 'bar',
output: 'const x = 1;',
},
],
},
],
},
],
});
`,
errors: [
Expand Down Expand Up @@ -459,6 +480,40 @@ ruleTester.run({
foo\`,
},
],
});
`,
output: `
ruleTester.run({
valid: [
{
code: 'foo',
},
{
code: \`
foo
\`,
},
{
code: \`
foo
\`,
},
],
invalid: [
{
code: 'foo',
},
{
code: \`
foo
\`,
},
{
code: \`
foo
\`,
},
],
});
`,
errors: [
Expand Down Expand Up @@ -508,6 +563,9 @@ ruleTester.run({
},
{
code: wrap`\`const a = "1";
${CODE_INDENT}\`.trimRight()`,
output: wrap`\`
const a = "1";
${CODE_INDENT}\`.trimRight()`,
errors: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-tslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"lodash": "^4.17.15"
},
"peerDependencies": {
"eslint": "^5.0.0 || ^6.0.0",
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0",
"tslint": "^5.0.0 || ^6.0.0",
"typescript": "*"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-tslint/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ruleTester = new TSESLint.RuleTester({
* within @typescript-eslint/parser
*/
project: './tests/fixture-project/tsconfig.json',
warnOnUnsupportedTypeScriptVersion: false,
},
parser: require.resolve('@typescript-eslint/parser'),
});
Expand Down Expand Up @@ -71,6 +72,7 @@ ruleTester.run('tslint/config', rule, {
{
options: [{ lintFile: './tests/test-project/tslint.json' }],
code: 'throw "err" // no-string-throw',
output: 'throw new Error("err") // no-string-throw',
filename: './tests/fixture-project/3.ts',
errors: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"peerDependencies": {
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^5.0.0 || ^6.0.0"
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0"
},
"peerDependenciesMeta": {
"typescript": {
Expand Down
16 changes: 10 additions & 6 deletions packages/eslint-plugin/src/rules/func-call-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export type Options = [
allowNewlines?: boolean;
}?,
];
export type MessageIds = 'unexpected' | 'missing';
export type MessageIds =
| 'unexpectedWhitespace'
| 'unexpectedNewline'
| 'missing';

export default util.createRule<Options, MessageIds>({
name: 'func-call-spacing',
Expand Down Expand Up @@ -56,8 +59,9 @@ export default util.createRule<Options, MessageIds>({
},

messages: {
unexpected:
'Unexpected space or newline between function name and paren.',
unexpectedWhitespace:
'Unexpected whitespace between function name and paren.',
unexpectedNewline: 'Unexpected newline between function name and paren.',
missing: 'Missing space between function name and paren.',
},
},
Expand Down Expand Up @@ -110,7 +114,7 @@ export default util.createRule<Options, MessageIds>({
return context.report({
node,
loc: lastCalleeToken.loc.start,
messageId: 'unexpected',
messageId: 'unexpectedWhitespace',
fix(fixer) {
/*
* Only autofix if there is no newline
Expand Down Expand Up @@ -140,7 +144,7 @@ export default util.createRule<Options, MessageIds>({
context.report({
node,
loc: lastCalleeToken.loc.start,
messageId: 'unexpected',
messageId: 'unexpectedWhitespace',
});
}
} else {
Expand All @@ -157,7 +161,7 @@ export default util.createRule<Options, MessageIds>({
context.report({
node,
loc: lastCalleeToken.loc.start,
messageId: 'unexpected',
messageId: 'unexpectedNewline',
fix(fixer) {
return fixer.replaceTextRange(
[lastCalleeToken.range[1], openingParenToken.range[0]],
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/no-empty-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const schema = util.deepMerge(
'constructors',
'private-constructors',
'protected-constructors',
'asyncFunctions',
'asyncMethods',
],
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/no-implied-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as tsutils from 'tsutils';
import * as util from '../util';

const FUNCTION_CONSTRUCTOR = 'Function';
const GLOBAL_CANDIDATES = new Set(['global', 'window', 'globalThis']);
const EVAL_LIKE_METHODS = new Set([
'setImmediate',
'setInterval',
Expand Down Expand Up @@ -46,7 +47,7 @@ export default util.createRule({
if (
node.type === AST_NODE_TYPES.MemberExpression &&
node.object.type === AST_NODE_TYPES.Identifier &&
node.object.name === 'window'
GLOBAL_CANDIDATES.has(node.object.name)
) {
if (node.property.type === AST_NODE_TYPES.Identifier) {
return node.property.name;
Expand Down
17 changes: 10 additions & 7 deletions packages/eslint-plugin/src/rules/space-before-function-paren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type FuncOption = Option | 'ignore';

export type Options = [
| Option
| Partial<{
anonymous: FuncOption;
named: FuncOption;
asyncArrow: FuncOption;
}>,
| {
anonymous?: FuncOption;
named?: FuncOption;
asyncArrow?: FuncOption;
},
];
export type MessageIds = 'unexpected' | 'missing';

Expand Down Expand Up @@ -150,7 +150,10 @@ export default util.createRule<Options, MessageIds>({
if (hasSpacing && functionConfig === 'never') {
context.report({
node,
loc: leftToken.loc.end,
loc: {
start: leftToken.loc.end,
end: rightToken.loc.start,
},
messageId: 'unexpected',
fix: fixer =>
fixer.removeRange([leftToken.range[1], rightToken.range[0]]),
Expand All @@ -162,7 +165,7 @@ export default util.createRule<Options, MessageIds>({
) {
context.report({
node,
loc: leftToken.loc.end,
loc: rightToken.loc,
messageId: 'missing',
fix: fixer => fixer.insertTextAfter(leftToken, ' '),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ fdescribe("foo", function() {
options: ['event'],
errors: [
{
message: "Unexpected use of 'event'.",
// the base rule doesn't use messageId
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
messageId: 'defaultMessage',
data: {
name: 'event',
},
},
],
},
{
Expand All @@ -77,10 +78,11 @@ confirm("TEST");
options: ['confirm'],
errors: [
{
message: "Unexpected use of 'confirm'.",
// the base rule doesn't use messageId
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
messageId: 'defaultMessage',
data: {
name: 'confirm',
},
},
],
},
{
Expand All @@ -90,10 +92,11 @@ var a = confirm("TEST")?.a;
options: ['confirm'],
errors: [
{
message: "Unexpected use of 'confirm'.",
// the base rule doesn't use messageId
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
messageId: 'defaultMessage',
data: {
name: 'confirm',
},
},
],
},
],
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/tests/rules/array-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ function fooFunction(foo: ArrayClass<string>[]) {
},
{
code: 'let fooVar: Array[];',
output: 'let fooVar: any[][];',
options: [{ default: 'array' }],
errors: [
{
Expand All @@ -729,6 +730,7 @@ function fooFunction(foo: ArrayClass<string>[]) {
},
{
code: 'let fooVar: Array[];',
output: 'let fooVar: any[][];',
options: [{ default: 'array-simple' }],
errors: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/tests/rules/ban-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ ruleTester.run('ban-types', rule, {
invalid: [
{
code: 'let a: String;',
output: 'let a: string;',
errors: [
{
messageId: 'bannedTypeMessage',
Expand Down
Loading