Skip to content

Commit

Permalink
[Tests] make sure parsers.TS is harder to misuse
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 23, 2021
1 parent 342ad24 commit af2d24a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions tests/helpers/parsers.js
Expand Up @@ -11,6 +11,9 @@ module.exports = {
TYPESCRIPT_ESLINT: path.join(__dirname, NODE_MODULES, 'typescript-eslint-parser'),
'@TYPESCRIPT_ESLINT': path.join(__dirname, NODE_MODULES, '@typescript-eslint/parser'),
TS: function TS(tests) {
if (!Array.isArray(tests) || arguments.length > 1) {
throw new SyntaxError('parsers.TS() takes a single array argument');
}
if (semver.satisfies(version, '>= 5')) {
return tests;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/boolean-prop-naming.js
Expand Up @@ -416,7 +416,7 @@ ruleTester.run('boolean-prop-naming', rule, {
rule: '^is[A-Z]([A-Za-z0-9]?)+',
validateNested: true
}]
}, parsers.TS({
}, parsers.TS([{
code: `
type TestFNType = {
isEnabled: boolean
Expand All @@ -428,7 +428,7 @@ ruleTester.run('boolean-prop-naming', rule, {
}],
parser: parsers['@TYPESCRIPT_ESLINT'],
errors: []
})),
}])),

invalid: [].concat({
// createReactClass components with PropTypes
Expand Down Expand Up @@ -956,7 +956,7 @@ ruleTester.run('boolean-prop-naming', rule, {
messageId: 'patternMismatch',
data: {propName: 'something', pattern: '^is[A-Z]([A-Za-z0-9]?)+'}
}]
}, parsers.TS({
}, parsers.TS([{
code: `
type TestConstType = {
enabled: boolean
Expand Down Expand Up @@ -984,5 +984,5 @@ ruleTester.run('boolean-prop-naming', rule, {
errors: [{
message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
}]
}))
}]))
});
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-key.js
Expand Up @@ -77,11 +77,11 @@ ruleTester.run('jsx-key', rule, {
code: '[1, 2, 3]?.map(x => <BabelEslintApp />)',
parser: parsers.BABEL_ESLINT,
errors: [{messageId: 'missingIterKey'}]
}, parsers.TS({
}, parsers.TS([{
code: '[1, 2, 3]?.map(x => <TypescriptEslintApp />)',
parser: parsers['@TYPESCRIPT_ESLINT'],
errors: [{messageId: 'missingIterKey'}]
}), {
}]), {
code: '[1, 2, 3].map(x => <>{x}</>);',
parser: parsers.BABEL_ESLINT,
options: [{checkFragmentShorthand: true}],
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/jsx-no-constructed-context-values.js
Expand Up @@ -106,7 +106,7 @@ ruleTester.run('react-no-constructed-context-values', rule, {
}
`
},
parsers.TS(
parsers.TS([
{
code: `
import React from 'react';
Expand Down Expand Up @@ -141,12 +141,12 @@ ruleTester.run('react-no-constructed-context-values', rule, {
`,
parser: parsers['@TYPESCRIPT_ESLINT']
}
),
]),
{
code: `
import React from 'react';
import BooleanContext from './BooleanContext';
function ContextProvider(props) {
return (
<BooleanContext.Provider value>
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/no-typos.js
Expand Up @@ -1856,7 +1856,7 @@ ruleTester.run('no-typos', rule, {
parserOptions: parserOptions
},
*/
}, parsers.TS({
}, parsers.TS([{
code: `
import 'prop-types'
`,
Expand All @@ -1874,5 +1874,5 @@ ruleTester.run('no-typos', rule, {
errors: [{
messageId: 'noPropTypesBinding'
}]
}))
}]))
});

0 comments on commit af2d24a

Please sign in to comment.