forked from jsx-eslint/eslint-plugin-react
-
Notifications
You must be signed in to change notification settings - Fork 0
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
31ef12a
commit 740bf7c
Showing
13 changed files
with
201 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
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.js'); | ||
|
||
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,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/flat-config/config-jsx-runtime/eslint.config.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.js'); | ||
const reactJSXRuntime = require('../../../../configs/jsx-runtime.js'); | ||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.jsx'], | ||
...reactRecommended, | ||
languageOptions: { | ||
...reactRecommended.languageOptions | ||
} | ||
}, | ||
reactJSXRuntime | ||
]; |
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.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.js'); | ||
|
||
module.exports = [{ | ||
files: ['**/*.jsx'], | ||
...reactRecommended, | ||
languageOptions: { | ||
...reactRecommended.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,3 @@ | ||
<div foo="hello"> | ||
test | ||
</div> |
18 changes: 18 additions & 0 deletions
18
tests/fixtures/flat-config/plugin-and-config/eslint.config.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.js'); | ||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.jsx'], | ||
plugins: { react } | ||
}, | ||
{ | ||
files: ['**/*.jsx'], | ||
...reactRecommended, | ||
languageOptions: { | ||
...reactRecommended.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,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,109 @@ | ||
/* 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'); | ||
}); | ||
}); | ||
|
||
it('should work when the plugin is used with "all" config', () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'config-all'), | ||
}); | ||
|
||
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', () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'config-recommended'), | ||
}); | ||
|
||
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', () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'config-jsx-runtime'), | ||
}); | ||
|
||
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', () => { | ||
const eslint = new ESLint({ | ||
cwd: path.resolve(fixturesdDir, 'plugin-and-config'), | ||
}); | ||
|
||
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'); | ||
}); | ||
}); | ||
}); |