Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: upgrade to ESLint v7 (#2022)
  • Loading branch information
bradzacher committed May 21, 2020
1 parent 7ad4d7c commit 208de71
Show file tree
Hide file tree
Showing 60 changed files with 1,699 additions and 1,746 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
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
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
Expand Up @@ -94,6 +94,7 @@ export default createRule({
suggest: [
{
messageId: 'suggestedFix',
data: banned,
fix(fixer): TSESLint.RuleFix | null {
if (banned.fixWith == null) {
return null;
Expand Down
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
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
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
Expand Up @@ -56,7 +56,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
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
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
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
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
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
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
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

0 comments on commit 208de71

Please sign in to comment.