Skip to content

Commit

Permalink
JS-401 Fix Babel plugin and preset imports (#4898)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez authored Nov 11, 2024
1 parent 5de6981 commit 6391608
Show file tree
Hide file tree
Showing 42 changed files with 116 additions and 160 deletions.
15 changes: 6 additions & 9 deletions packages/jsts/src/parsers/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { Linter } from 'eslint';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import babelPresetReact from '@babel/preset-react';
import babelPresetFlow from '@babel/preset-flow';
import babelPresetEnv from '@babel/preset-env';
import babelPluginDecorators from '@babel/plugin-proposal-decorators';

/**
* Builds ESLint parser options
Expand Down Expand Up @@ -72,15 +74,10 @@ export function buildParserOptions(initialOptions: Linter.ParserOptions, usingBa
* @returns the extend parser options
*/
function babelParserOptions(options: Linter.ParserOptions) {
const pluginPath = `${dirname(fileURLToPath(import.meta.url))}/../../../../node_modules`;
const babelOptions = {
targets: 'defaults',
presets: [
`${pluginPath}/@babel/preset-react`,
`${pluginPath}/@babel/preset-flow`,
`${pluginPath}/@babel/preset-env`,
],
plugins: [[`${pluginPath}/@babel/plugin-proposal-decorators`, { version: '2022-03' }]],
presets: [babelPresetReact, babelPresetFlow, babelPresetEnv],
plugins: [[babelPluginDecorators, { version: '2022-03' }]],
babelrc: false,
configFile: false,
parserOpts: {
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S100/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

Expand Down
7 changes: 3 additions & 4 deletions packages/jsts/src/rules/S101/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: { ecmaVersion: 2018 },
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

const DEFAULT_FORMAT = '^[A-Z][a-zA-Z0-9]*$';
Expand Down
7 changes: 2 additions & 5 deletions packages/jsts/src/rules/S1110/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import { fileURLToPath } from 'node:url';

// @typescript-eslint/parser is required for the type assertion test at the end of this test file
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
parser: tsParserPath,
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
});

ruleTester.run('Redundant pairs of parentheses should be removed', rule, {
Expand Down
9 changes: 4 additions & 5 deletions packages/jsts/src/rules/S1128/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import path from 'path';
import { BabelRuleTester } from '../../../tests/tools/index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const babelRuleTester = BabelRuleTester();

Expand Down Expand Up @@ -193,7 +192,7 @@ bar();`),

const ruleTesterTS = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
});

ruleTesterTS.run('Unnecessary imports should be removed', rule, {
Expand Down Expand Up @@ -348,7 +347,7 @@ const ruleTesterJsxFactory = new NodeRuleTester({
ecmaFeatures: { jsx: true },
project,
},
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
});

ruleTesterJsxFactory.run('Unused imports denoting jsx factory should be ignored', rule, {
Expand Down Expand Up @@ -409,7 +408,7 @@ ruleTesterJsxFactory.run('Unused imports denoting jsx factory should be ignored'

const ruleTesterVue = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
parser: require.resolve('vue-eslint-parser'),
parser: fileURLToPath(import.meta.resolve('vue-eslint-parser')),
});

ruleTesterVue.run('Unnecessary imports should be removed', rule, {
Expand Down
7 changes: 3 additions & 4 deletions packages/jsts/src/rules/S117/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: { ecmaVersion: 2018 },
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

const DEFAULT_FORMAT = '^[_$A-Za-z][$A-Za-z0-9]*$|^[_$A-Z][_$A-Z0-9]+$';
Expand Down
6 changes: 3 additions & 3 deletions packages/jsts/src/rules/S1172/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import { Scope } from 'eslint';
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { isParameterProperty, rule } from './rule.js';
import Module from 'node:module';
import { it } from 'node:test';
import { expect } from 'expect';
const require = Module.createRequire(import.meta.url);

import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

Expand Down
8 changes: 3 additions & 5 deletions packages/jsts/src/rules/S1226/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';

import { rule } from './index.js';
import { fileURLToPath } from 'node:url';

import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
parser: tsParserPath,
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

const NON_COMPLIANT_REGEX = /\/\/\sNoncompliant\s{{(\w+)}}/;
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S131/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import { rule } from './index.js';
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { TypeScriptRuleTester } from '../../../tests/tools/index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018 },
});
ruleTester.run('"switch" statements should have "default" clauses', rule, {
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S1530/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
Expand Down Expand Up @@ -75,7 +74,7 @@ ruleTester.run(`Function declarations should not be made within blocks`, rule, {
});

const ruleTesterTS = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
});

Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S1533/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import { fileURLToPath } from 'node:url';

import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const tsParserPath = fileURLToPath(import.meta.resolve('@typescript-eslint/parser'));
const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018 },
parser: tsParserPath,
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S2068/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import path from 'path';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
});

Expand Down
7 changes: 3 additions & 4 deletions packages/jsts/src/rules/S2430/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: { ecmaVersion: 2018 },
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

ruleTester.run(`A constructor name should not start with a lowercase letter`, rule, {
Expand Down
7 changes: 3 additions & 4 deletions packages/jsts/src/rules/S3498/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: { ecmaVersion: 2018 },
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, ecmaFeatures: { jsx: true } },
});

ruleTester.run(`Object literal shorthand syntax should be used`, rule, {
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S3516/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import { fileURLToPath } from 'node:url';

import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const tsParserPath = fileURLToPath(import.meta.resolve('@typescript-eslint/parser'));
const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018 },
parser: tsParserPath,
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S3524/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018 },
});

Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S3776/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import { IssueLocation } from '../helpers/index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module', ecmaFeatures: { jsx: true } },
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
});

ruleTester.run('cognitive-complexity', rule, {
Expand Down
6 changes: 2 additions & 4 deletions packages/jsts/src/rules/S3798/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { BabelRuleTester } from '../../../tests/tools/index.js';
import { rule } from './index.js';
import { fileURLToPath } from 'node:url';

import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const ruleTester = new NodeRuleTester({
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
parser: tsParserPath,
});
const ruleTesterwithBrowser = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S3801/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import { fileURLToPath } from 'node:url';

import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const tsParserPath = fileURLToPath(import.meta.resolve('@typescript-eslint/parser'));
const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018 },
parser: tsParserPath,
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S4123/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import { rule } from './index.js';
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { JavaScriptRuleTester, TypeScriptRuleTester } from '../../../tests/tools/index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new TypeScriptRuleTester();
ruleTester.run('await should only be used with promises.', rule, {
Expand Down Expand Up @@ -219,7 +218,7 @@ ruleTester.run('await should only be used with promises.', rule, {
});

const ruleTesterWithNoFullTypeInfo = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S4144/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './rule.js';
import { expandMessage, IssueLocation } from '../helpers/index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module', ecmaFeatures: { jsx: true } },
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
});

ruleTester.run('no-identical-functions', rule, {
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S4275/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
*/
import { rule } from './index.js';
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { fileURLToPath } from 'node:url';

import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
const tsParserPath = require.resolve('@typescript-eslint/parser');
const tsParserPath = fileURLToPath(import.meta.resolve('@typescript-eslint/parser'));
const ruleTester = new NodeRuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: 'module' },
parser: tsParserPath,
Expand Down
5 changes: 2 additions & 3 deletions packages/jsts/src/rules/S4322/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
*/
import { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import Module from 'node:module';
const require = Module.createRequire(import.meta.url);
import { fileURLToPath } from 'node:url';

const ruleTester = new NodeRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parser: fileURLToPath(import.meta.resolve('@typescript-eslint/parser')),
parserOptions: { ecmaVersion: 2018 },
});

Expand Down
Loading

0 comments on commit 6391608

Please sign in to comment.