-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4be7f0e
commit a32c0ad
Showing
17 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/fixtures/flat-config/config-all/eslint.config-deep.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const reactAll = require('../../../../configs/all'); | ||
|
||
module.exports = [{ | ||
files: ['**/*.jsx'], | ||
...reactAll, | ||
languageOptions: { | ||
...reactAll.languageOptions | ||
} | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
const reactPlugin = require('../../../..'); | ||
|
||
module.exports = [{ | ||
files: ['**/*.jsx'], | ||
...reactPlugin.configs['flat/all'] | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/flat-config/config-jsx-runtime/eslint.config-deep.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const reactRecommended = require('../../../../configs/recommended'); | ||
const reactJSXRuntime = require('../../../../configs/jsx-runtime'); | ||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.jsx'], | ||
...reactRecommended, | ||
languageOptions: { | ||
...reactRecommended.languageOptions | ||
} | ||
}, | ||
reactJSXRuntime | ||
]; |
11 changes: 11 additions & 0 deletions
11
tests/fixtures/flat-config/config-jsx-runtime/eslint.config-root.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const reactPlugin = require('../../../..'); | ||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.jsx'], | ||
...reactPlugin.configs['flat/recommended'] | ||
}, | ||
reactPlugin.configs['flat/jsx-runtime'] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
11 changes: 11 additions & 0 deletions
11
tests/fixtures/flat-config/config-recommended/eslint.config-deep.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const reactRecommended = require('../../../../configs/recommended'); | ||
|
||
module.exports = [{ | ||
files: ['**/*.jsx'], | ||
...reactRecommended, | ||
languageOptions: { | ||
...reactRecommended.languageOptions | ||
} | ||
}]; |
8 changes: 8 additions & 0 deletions
8
tests/fixtures/flat-config/config-recommended/eslint.config-root.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
const reactPlugin = require('../../../..'); | ||
|
||
module.exports = [{ | ||
files: ['**/*.jsx'], | ||
...reactPlugin.configs['flat/recommended'] | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
18 changes: 18 additions & 0 deletions
18
tests/fixtures/flat-config/plugin-and-config/eslint.config-deep.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const react = require('../../../..'); | ||
const reactRecommended = require('../../../../configs/recommended'); | ||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.jsx'], | ||
plugins: { react } | ||
}, | ||
{ | ||
files: ['**/*.jsx'], | ||
...reactRecommended, | ||
languageOptions: { | ||
...reactRecommended.languageOptions | ||
} | ||
} | ||
]; |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/flat-config/plugin-and-config/eslint.config-root.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const react = require('../../../..'); | ||
const reactRecommended = require('../../../../configs/recommended'); | ||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.jsx'], | ||
plugins: { react } | ||
}, | ||
{ | ||
files: ['**/*.jsx'], | ||
...react.configs['flat/recommended'] | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const react = require('../../../..'); | ||
|
||
module.exports = [{ | ||
files: ['**/*.jsx'], | ||
languageOptions: { | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
}, | ||
plugins: { | ||
react, | ||
}, | ||
rules: { | ||
'react/jsx-no-literals': 1, | ||
}, | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* eslint-env mocha */ | ||
|
||
'use strict'; | ||
|
||
const semver = require('semver'); | ||
const eslintPkg = require('eslint/package.json'); | ||
|
||
if (!semver.satisfies(eslintPkg.version, '>= 8.57.0')) { | ||
return; | ||
} | ||
|
||
const ESLint = semver.major(eslintPkg.version) < 9 | ||
? require('eslint/use-at-your-own-risk').FlatESLint // eslint-disable-line import/no-unresolved -- false positive | ||
: require('eslint').ESLint; | ||
|
||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
describe('eslint-plugin-react in flat config', () => { | ||
const fixturesdDir = path.resolve(__dirname, 'fixtures', 'flat-config'); | ||
|
||
it('should work when the plugin is used directly', () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'plugin'), | ||
}); | ||
|
||
return eslint.lintFiles(['test.jsx']).then((results) => { | ||
const result = results[0]; | ||
|
||
assert.strictEqual(result.messages.length, 1); | ||
assert.strictEqual(result.messages[0].severity, 1); | ||
assert.strictEqual(result.messages[0].ruleId, 'react/jsx-no-literals'); | ||
assert.strictEqual(result.messages[0].messageId, 'literalNotInJSXExpression'); | ||
}); | ||
}); | ||
|
||
['root', 'deep'].forEach((configAccess) => { | ||
const overrideConfigFile = `eslint.config-${configAccess}.js`; | ||
|
||
it(`should work when the plugin is used with "all" config (${configAccess})`, () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'config-all'), | ||
overrideConfigFile, | ||
}); | ||
|
||
return eslint.lintFiles(['test.jsx']).then((results) => { | ||
const result = results[0]; | ||
|
||
assert.strictEqual(result.messages.length, 3); | ||
assert.strictEqual(result.messages[0].severity, 2); | ||
assert.strictEqual(result.messages[0].ruleId, 'react/react-in-jsx-scope'); | ||
assert.strictEqual(result.messages[0].messageId, 'notInScope'); | ||
assert.strictEqual(result.messages[1].severity, 2); | ||
assert.strictEqual(result.messages[1].ruleId, 'react/no-unknown-property'); | ||
assert.strictEqual(result.messages[1].messageId, 'unknownProp'); | ||
assert.strictEqual(result.messages[2].severity, 2); | ||
assert.strictEqual(result.messages[2].ruleId, 'react/jsx-no-literals'); | ||
assert.strictEqual(result.messages[2].messageId, 'literalNotInJSXExpression'); | ||
}); | ||
}); | ||
|
||
it(`should work when the plugin is used with "recommended" config (${configAccess})`, () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'config-recommended'), | ||
overrideConfigFile, | ||
}); | ||
|
||
return eslint.lintFiles(['test.jsx']).then((results) => { | ||
const result = results[0]; | ||
|
||
assert.strictEqual(result.messages.length, 2); | ||
assert.strictEqual(result.messages[0].severity, 2); | ||
assert.strictEqual(result.messages[0].ruleId, 'react/react-in-jsx-scope'); | ||
assert.strictEqual(result.messages[0].messageId, 'notInScope'); | ||
assert.strictEqual(result.messages[1].severity, 2); | ||
assert.strictEqual(result.messages[1].ruleId, 'react/no-unknown-property'); | ||
assert.strictEqual(result.messages[1].messageId, 'unknownProp'); | ||
}); | ||
}); | ||
|
||
it(`should work when the plugin is used with "recommended" and "jsx-runtime" configs (${configAccess})`, () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'config-jsx-runtime'), | ||
overrideConfigFile, | ||
}); | ||
|
||
return eslint.lintFiles(['test.jsx']).then((results) => { | ||
const result = results[0]; | ||
|
||
assert.strictEqual(result.messages.length, 1); | ||
assert.strictEqual(result.messages[0].severity, 2); | ||
assert.strictEqual(result.messages[0].ruleId, 'react/no-unknown-property'); | ||
assert.strictEqual(result.messages[0].messageId, 'unknownProp'); | ||
}); | ||
}); | ||
|
||
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3693 | ||
it(`should work when the plugin is used directly and with "recommended" config (${configAccess})`, () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'plugin-and-config'), | ||
overrideConfigFile, | ||
}); | ||
|
||
return eslint.lintFiles(['test.jsx']).then((results) => { | ||
const result = results[0]; | ||
|
||
assert.strictEqual(result.messages.length, 2); | ||
assert.strictEqual(result.messages[0].severity, 2); | ||
assert.strictEqual(result.messages[0].ruleId, 'react/react-in-jsx-scope'); | ||
assert.strictEqual(result.messages[0].messageId, 'notInScope'); | ||
assert.strictEqual(result.messages[1].severity, 2); | ||
assert.strictEqual(result.messages[1].ruleId, 'react/no-unknown-property'); | ||
assert.strictEqual(result.messages[1].messageId, 'unknownProp'); | ||
}); | ||
}); | ||
}); | ||
}); |