-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
ESLint 9 #34
ESLint 9 #34
Changes from 5 commits
d2586be
b15fc9c
8dac4df
cc75ad5
92e5b03
b1f2973
4cf2cdf
2907cda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ import { | |
} from './config'; | ||
import rule from './prefer-arrow-functions'; | ||
|
||
// TODO: Remove this once Jest starts supporting modern JavaScript | ||
globalThis.structuredClone ??= obj => JSON.parse(JSON.stringify(obj)); | ||
|
||
const alwaysValid = [ | ||
{ | ||
code: 'var foo = (bar) => bar;', | ||
|
@@ -492,14 +495,6 @@ const invalidAndHasBlockStatement = [ | |
code: 'async function foo(a) { console.log(3); }', | ||
output: 'const foo = async (a) => { console.log(3); };', | ||
}, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
code: 'function foo(a) { console.log(3); }', | ||
output: 'const foo = (a) => { console.log(3); };', | ||
}, | ||
{ | ||
code: 'async function foo(a) { console.log(3); }', | ||
output: 'const foo = async (a) => { console.log(3); };', | ||
}, | ||
|
||
// https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/issues/28 | ||
{ | ||
|
@@ -576,22 +571,6 @@ const invalidAndHasBlockStatement = [ | |
code: 'var foo = async function() { console.log({a: false}); }', | ||
output: 'var foo = async () => { console.log({a: false}); }', | ||
}, | ||
{ | ||
code: 'var foo = function() { console.log({a: false}); }', | ||
output: 'var foo = () => { console.log({a: false}); }', | ||
}, | ||
{ | ||
code: 'var foo = async function() { console.log({a: false}); }', | ||
output: 'var foo = async () => { console.log({a: false}); }', | ||
}, | ||
{ | ||
code: 'function foo(a) { console.log({a: false}); }', | ||
output: 'const foo = (a) => { console.log({a: false}); };', | ||
}, | ||
{ | ||
code: 'async function foo(a) { console.log({a: false}); }', | ||
output: 'const foo = async (a) => { console.log({a: false}); };', | ||
}, | ||
{ | ||
code: 'function foo(a) { console.log({a: false}); }', | ||
output: 'const foo = (a) => { console.log({a: false}); };', | ||
|
@@ -614,22 +593,6 @@ const invalidAndHasBlockStatement = [ | |
code: 'var foo = async function() {\n console.log("World");\n}', | ||
output: 'var foo = async () => {\n console.log("World");\n}', | ||
}, | ||
{ | ||
code: 'var foo = function() {\n console.log("World");\n}', | ||
output: 'var foo = () => {\n console.log("World");\n}', | ||
}, | ||
{ | ||
code: 'var foo = async function() {\n console.log("World");\n}', | ||
output: 'var foo = async () => {\n console.log("World");\n}', | ||
}, | ||
{ | ||
code: 'function foo(a) {\n console.log(3);\n}', | ||
output: 'const foo = (a) => {\n console.log(3);\n};', | ||
}, | ||
{ | ||
code: 'async function foo(a) {\n console.log(3);\n}', | ||
output: 'const foo = async (a) => {\n console.log(3);\n};', | ||
}, | ||
{ | ||
code: 'function foo(a) {\n console.log(3);\n}', | ||
output: 'const foo = (a) => {\n console.log(3);\n};', | ||
|
@@ -750,7 +713,6 @@ const validWhenAllowNamedFunctions = [ | |
{ | ||
// Make sure "allowNamedFunctions" works with typescript | ||
code: '() => { function foo(a: string): string { return `bar ${a}`;} }', | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
}, | ||
]; | ||
|
||
|
@@ -768,10 +730,6 @@ const invalidWhenAllowNamedFunctions = [ | |
code: '() => { var foo = function() { return () => "bar"; }; }', | ||
output: '() => { var foo = () => () => "bar"; }', | ||
}, | ||
{ | ||
code: '() => { var foo = function() { return "bar"; }; }', | ||
output: '() => { var foo = () => "bar"; }', | ||
}, | ||
{ | ||
code: 'module.exports = () => { var foo = function() { return "bar"; }; }', | ||
output: 'module.exports = () => { var foo = () => "bar"; }', | ||
|
@@ -809,16 +767,15 @@ const invalidWhenAllowNamedFunctions = [ | |
output: `function foo(a: string): () => string { | ||
return () => \`bar \${a}\`; | ||
}`, | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
}, | ||
]; | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
parserOptions: { | ||
ecmaFeatures: { jsx: false }, | ||
ecmaVersion: 8, | ||
sourceType: 'module', | ||
// TODO: Remove this `languageOptions` once the tests are updated for flat config: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the tests are updated to support flat config, this can go back to the original values. The new default for |
||
languageOptions: { | ||
ecmaVersion: 5, // Original value was 8 here | ||
parser: require('@typescript-eslint/parser'), | ||
sourceType: 'script' // Original value was 'module' here | ||
}, | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ export default { | |
const classPropertiesAllowed = getOption('classPropertiesAllowed'); | ||
const disallowPrototype = getOption('disallowPrototype'); | ||
const returnStyle = getOption('returnStyle'); | ||
const sourceCode = context.getSourceCode(); | ||
const { sourceCode } = context; | ||
|
||
const isBlockStatementWithSingleReturn = (node) => { | ||
return ( | ||
|
@@ -193,8 +193,8 @@ export default { | |
}; | ||
|
||
const isPrototypeAssignment = (node) => { | ||
return context | ||
.getAncestors() | ||
return sourceCode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the "key" changes, made following the official documentation. |
||
.getAncestors(node) | ||
.reverse() | ||
.some((ancestor) => { | ||
const isPropertyOfReplacementPrototypeObject = | ||
|
@@ -216,8 +216,8 @@ export default { | |
}; | ||
|
||
const isWithinClassBody = (node) => { | ||
return context | ||
.getAncestors() | ||
return sourceCode | ||
.getAncestors(node) | ||
.reverse() | ||
.some((ancestor) => { | ||
return ancestor.type === 'ClassBody'; | ||
|
@@ -334,4 +334,4 @@ export default { | |
}, | ||
}; | ||
}, | ||
}; | ||
} as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like ESLint now uses structuredClone so we need to "mock" it for Jest because Jest doesn't support that yet.