diff --git a/.eslintrc.json b/.eslintrc.json index ccebb16..f137603 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,11 +11,13 @@ "eslint:all", "prettier", - "plugin:n/recommended" + // Need to be specific, because this config is one level above the package.jsons that have type:module + "plugin:n/recommended-module" ], "plugins": ["import"], "parserOptions": { - "ecmaVersion": 2022 + "ecmaVersion": 2022, + "sourceType": "module" }, "env": { "es2021": true, @@ -36,6 +38,7 @@ "no-ternary": "off", "no-undefined": "off", "one-var": "off", + "sort-imports": "off", // using import/order instead "sort-keys": "off", "strict": "off", @@ -64,13 +67,11 @@ { "blankLine": "always", "prev": "*", "next": ["cjs-export"] }, { "blankLine": "always", "prev": "*", "next": "block-like" }, - { "blankLine": "always", "prev": "block-like", "next": "*" }, - - { "blankLine": "always", "prev": "cjs-import", "next": "*" }, - { "blankLine": "any", "prev": "cjs-import", "next": "cjs-import" } + { "blankLine": "always", "prev": "block-like", "next": "*" } ], - // eslint-plugin-import - Selection from the ones that are compatible with CommonJS + // eslint-plugin-import - selection (not comprehensive) + "import/newline-after-import": "error", "import/no-extraneous-dependencies": "error", "import/order": ["error", { "newlines-between": "never" }] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d721f01..23ae0ef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,7 @@ Different versions may work, but majorly newer/older tooling versions are likely - Verify there are no uncommitted changes - `npm run ci` in root - `npm run lint` in the example project, check number of errors and presence of new expected ones -- `../check-es-compat/bin/cli.mjs .` in the example project, it should produce the same errors +- `../check-es-compat/bin/cli.js .` in the example project, it should produce the same errors - `lerna clean` then `lerna bootstrap`, verify no changes were introduced (e.g. to `package-lock.json`) ## Releasing diff --git a/package.json b/package.json index 4d18c90..1f341ec 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "private": true, "scripts": { "check": "npm-run-all --parallel check:*", - "check:lint": "eslint --no-eslintrc --config=.eslintrc.json **/*.{js,mjs}", - "check:prettier": "prettier --check **/*.{js,json,md,mjs}", + "check:lint": "eslint --no-eslintrc --config=.eslintrc.json **/*.js", + "check:prettier": "prettier --check **/*.{js,json,md}", "ci": "npm-run-all check test", "postinstall": "lerna bootstrap", "test": "lerna run test" diff --git a/packages/check-es-compat/bin/cli.mjs b/packages/check-es-compat/bin/cli.js similarity index 100% rename from packages/check-es-compat/bin/cli.mjs rename to packages/check-es-compat/bin/cli.js diff --git a/packages/check-es-compat/package.json b/packages/check-es-compat/package.json index ea457e0..1ef0670 100644 --- a/packages/check-es-compat/package.json +++ b/packages/check-es-compat/package.json @@ -26,8 +26,9 @@ }, "license": "MIT", "author": "Robat Williams", + "type": "module", "bin": { - "check-es-compat": "bin/cli.mjs" + "check-es-compat": "bin/cli.js" }, "dependencies": { "eslint": "^8.56.0", diff --git a/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.js b/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.js index 8bfd4c5..094de15 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.js @@ -1,4 +1,4 @@ -module.exports = function compareVersions(a, b) { +export default function compareVersions(a, b) { const aParts = a.split('.').map(Number); const bParts = b.split('.').map(Number); @@ -12,4 +12,4 @@ module.exports = function compareVersions(a, b) { } return 0; -}; +} diff --git a/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.test.js b/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.test.js index 9ee1fa6..e3eb8db 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.test.js @@ -1,6 +1,6 @@ -const assert = require('node:assert'); -const { test } = require('node:test'); -const compareVersions = require('./compareVersions'); +import assert from 'node:assert'; +import { test } from 'node:test'; +import compareVersions from './compareVersions.js'; test('equal', () => { assert.strictEqual(compareVersions('1.2.3', '1.2.3'), 0); diff --git a/packages/eslint-plugin-ecmascript-compat/lib/compatibility.js b/packages/eslint-plugin-ecmascript-compat/lib/compatibility.js index 1a96d11..4a5fac8 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/compatibility.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/compatibility.js @@ -1,7 +1,7 @@ /* eslint-disable camelcase, no-underscore-dangle */ -const compareVersions = require('./compareVersions'); +import compareVersions from './compareVersions.js'; -function unsupportedFeatures(features, targets) { +export function unsupportedFeatures(features, targets) { return features.filter((feature) => !isFeatureSupportedByTargets(feature, targets)); } @@ -54,5 +54,3 @@ function interpretSupport(versionAdded) { isVersionUnknown: versionAdded === true, }; } - -module.exports = { unsupportedFeatures }; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/compatibility.test.js b/packages/eslint-plugin-ecmascript-compat/lib/compatibility.test.js index 7fcc958..07933fc 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/compatibility.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/compatibility.test.js @@ -1,8 +1,8 @@ /* eslint-disable camelcase */ -const assert = require('node:assert'); -const { it } = require('node:test'); -const { unsupportedFeatures } = require('./compatibility'); -const features = require('./features'); +import assert from 'node:assert'; +import { it } from 'node:test'; +import { unsupportedFeatures } from './compatibility.js'; +import features from './features/index.js'; it('supports feature in version introduced', () => { const feature = { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/delegation.js b/packages/eslint-plugin-ecmascript-compat/lib/delegation.js index a681c82..ea24e8f 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/delegation.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/delegation.js @@ -1,4 +1,4 @@ -function createDelegatee(config, rootContext) { +export function createDelegatee(config, rootContext) { const { definition, options } = config; if (!definition) { @@ -44,7 +44,7 @@ function createDelegatee(config, rootContext) { return definition.create(context); } -function delegatingVisitor(delegatees) { +export function delegatingVisitor(delegatees) { const delegator = {}; delegatees.forEach((visitor) => { @@ -63,5 +63,3 @@ function delegatingVisitor(delegatees) { return delegator; } - -module.exports = { createDelegatee, delegatingVisitor }; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/delegation.test.js b/packages/eslint-plugin-ecmascript-compat/lib/delegation.test.js index ec113d2..d59f116 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/delegation.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/delegation.test.js @@ -1,5 +1,5 @@ -const eslint = require('eslint'); -const { createDelegatee, delegatingVisitor } = require('./delegation'); +import eslint from 'eslint'; +import { createDelegatee, delegatingVisitor } from './delegation.js'; const ruleTester = new eslint.RuleTester(); diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.js index 2a75f24..1d3616a 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.js @@ -1,11 +1,12 @@ -const eslint = require('eslint'); -const esPlugin = require('eslint-plugin-es-x'); -const compatData = require('@mdn/browser-compat-data'); -const { noRestrictedSyntaxPrototypeMethod } = require('./ruleOptionsUtil'); +import eslint from 'eslint'; +import esPlugin from 'eslint-plugin-es-x'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import { noRestrictedSyntaxPrototypeMethod } from './ruleOptionsUtil.js'; const coreRules = new eslint.Linter().getRules(); -module.exports = [ +export default [ { ruleConfig: { definition: coreRules.get('no-restricted-syntax'), diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.test.js index 353f162..ead5897 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 46'; @@ -9,7 +10,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: 'foo.includes();', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.js index 6d92df3..06c8dda 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.js @@ -1,11 +1,12 @@ -const eslint = require('eslint'); -const esPlugin = require('eslint-plugin-es-x'); -const compatData = require('@mdn/browser-compat-data'); -const { noRestrictedSyntaxPrototypeMethod } = require('./ruleOptionsUtil'); +import eslint from 'eslint'; +import esPlugin from 'eslint-plugin-es-x'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import { noRestrictedSyntaxPrototypeMethod } from './ruleOptionsUtil.js'; const coreRules = new eslint.Linter().getRules(); -module.exports = [ +export default [ { ruleConfig: { definition: esPlugin.rules['no-async-functions'] }, compatFeatures: [ diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.test.js index 2dccf83..cb26f4e 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 53'; @@ -16,7 +17,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: 'Object.getOwnPropertyDescriptors();', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.js index ffecb53..b2dea54 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.js @@ -1,11 +1,12 @@ -const eslint = require('eslint'); -const esPlugin = require('eslint-plugin-es-x'); -const compatData = require('@mdn/browser-compat-data'); -const { noRestrictedSyntaxPrototypeMethod } = require('./ruleOptionsUtil'); +import eslint from 'eslint'; +import esPlugin from 'eslint-plugin-es-x'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import { noRestrictedSyntaxPrototypeMethod } from './ruleOptionsUtil.js'; const coreRules = new eslint.Linter().getRules(); -module.exports = [ +export default [ { ruleConfig: { definition: esPlugin.rules['no-async-iteration'] }, compatFeatures: [ diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.test.js index b69d4a7..6126a79 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 59'; @@ -9,7 +10,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: 'foo.finally();', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.js index 3b994d2..84cad2a 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.js @@ -1,11 +1,12 @@ -const eslint = require('eslint'); -const esPlugin = require('eslint-plugin-es-x'); -const compatData = require('@mdn/browser-compat-data'); -const { noRestrictedSyntaxPrototypeMethod } = require('./ruleOptionsUtil'); +import eslint from 'eslint'; +import esPlugin from 'eslint-plugin-es-x'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import { noRestrictedSyntaxPrototypeMethod } from './ruleOptionsUtil.js'; const coreRules = new eslint.Linter().getRules(); -module.exports = [ +export default [ { ruleConfig: { definition: coreRules.get('no-restricted-syntax'), diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.test.js index 78240f0..c9deb40 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 65'; @@ -9,7 +10,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: 'const flat = residentialAddress.flat;', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.js index b9af7a7..768abe3 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.js @@ -1,11 +1,12 @@ -const eslint = require('eslint'); -const esPlugin = require('eslint-plugin-es-x'); -const compatData = require('@mdn/browser-compat-data'); -const { noRestrictedSyntaxPrototypeMethod } = require('./ruleOptionsUtil'); +import eslint from 'eslint'; +import esPlugin from 'eslint-plugin-es-x'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import { noRestrictedSyntaxPrototypeMethod } from './ruleOptionsUtil.js'; const coreRules = new eslint.Linter().getRules(); -module.exports = [ +export default [ { ruleConfig: { definition: coreRules.get('no-restricted-properties'), diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.test.js index b24d386..db13ee6 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 62'; @@ -20,7 +21,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: 'globalThis.foo;', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.js index 8d4f503..3257d03 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.js @@ -1,11 +1,12 @@ -const eslint = require('eslint'); -const compatData = require('@mdn/browser-compat-data'); -const esPlugin = require('eslint-plugin-es-x'); -const { noRestrictedSyntaxPrototypeMethod } = require('./ruleOptionsUtil'); +import eslint from 'eslint'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import esPlugin from 'eslint-plugin-es-x'; +import { noRestrictedSyntaxPrototypeMethod } from './ruleOptionsUtil.js'; const coreRules = new eslint.Linter().getRules(); -module.exports = [ +export default [ { ruleConfig: { definition: coreRules.get('no-restricted-syntax'), diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.test.js index a507fba..b6a1d84 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 74'; @@ -16,7 +17,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: '"A dog".replaceAll("dog", "monkey");', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.js index 889d22e..d363b3c 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.js @@ -1,7 +1,8 @@ -const compatData = require('@mdn/browser-compat-data'); -const esPlugin = require('eslint-plugin-es-x'); +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import esPlugin from 'eslint-plugin-es-x'; -module.exports = [ +export default [ { ruleConfig: { definition: esPlugin.rules['no-array-string-prototype-at'], diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.test.js index 9f24d7e..e158ac2 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 71'; @@ -10,7 +11,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: '[].at(1);', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.js index 8d54bfa..1c1a087 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.js @@ -1,7 +1,8 @@ -const compatData = require('@mdn/browser-compat-data'); -const esPlugin = require('eslint-plugin-es-x'); +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import esPlugin from 'eslint-plugin-es-x'; -module.exports = [ +export default [ { ruleConfig: { definition: esPlugin.rules['no-array-prototype-findlast-findlastindex'], diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.test.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.test.js index 7000294..ba8df4a 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.test.js @@ -1,4 +1,5 @@ -const { RuleTester } = require('eslint'); +import { RuleTester } from 'eslint'; +import rule from '../rule.js'; // Browser that doesn't support any features of this version - see es-versions.md process.env.BROWSERSLIST = 'Chrome >= 73'; @@ -9,7 +10,7 @@ const ruleTester = new RuleTester({ }, }); -ruleTester.run('compat', require('../rule'), { +ruleTester.run('compat', rule, { valid: [ { code: '[].findLast("a");', diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/index.js b/packages/eslint-plugin-ecmascript-compat/lib/features/index.js index 198836f..139983e 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/index.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/index.js @@ -1,10 +1,19 @@ -module.exports = [ - ...require('./es2016'), - ...require('./es2017'), - ...require('./es2018'), - ...require('./es2019'), - ...require('./es2020'), - ...require('./es2021'), - ...require('./es2022'), - ...require('./es2023'), +import es2016 from './es2016.js'; +import es2017 from './es2017.js'; +import es2018 from './es2018.js'; +import es2019 from './es2019.js'; +import es2020 from './es2020.js'; +import es2021 from './es2021.js'; +import es2022 from './es2022.js'; +import es2023 from './es2023.js'; + +export default [ + ...es2016, + ...es2017, + ...es2018, + ...es2019, + ...es2020, + ...es2021, + ...es2022, + ...es2023, ]; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/ruleOptionsUtil.js b/packages/eslint-plugin-ecmascript-compat/lib/features/ruleOptionsUtil.js index e09362e..b14518a 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/ruleOptionsUtil.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/ruleOptionsUtil.js @@ -1,4 +1,4 @@ -function noRestrictedSyntaxPrototypeMethod(method, esVersionName) { +export function noRestrictedSyntaxPrototypeMethod(method, esVersionName) { const [builtin, , name] = method.split('.'); const message = `${esVersionName} method '${method}' is forbidden`; @@ -13,7 +13,3 @@ function noRestrictedSyntaxPrototypeMethod(method, esVersionName) { }, ]; } - -module.exports = { - noRestrictedSyntaxPrototypeMethod, -}; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/index.js b/packages/eslint-plugin-ecmascript-compat/lib/index.js index b61ba40..3e27994 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/index.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/index.js @@ -1,4 +1,6 @@ -module.exports = { +import rule from './rule.js'; + +export default { configs: { recommended: { plugins: ['ecmascript-compat'], @@ -8,6 +10,6 @@ module.exports = { }, }, rules: { - compat: require('./rule'), + compat: rule, }, }; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/rule.js b/packages/eslint-plugin-ecmascript-compat/lib/rule.js index c7911d8..993ea0b 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/rule.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/rule.js @@ -1,9 +1,9 @@ -const compatibility = require('./compatibility'); -const { createDelegatee, delegatingVisitor } = require('./delegation'); -const features = require('./features'); -const targetRuntimes = require('./targetRuntimes'); +import * as compatibility from './compatibility.js'; +import { createDelegatee, delegatingVisitor } from './delegation.js'; +import features from './features/index.js'; +import targetRuntimes from './targetRuntimes.js'; -module.exports = { +export default { meta: { type: 'problem', schema: [ diff --git a/packages/eslint-plugin-ecmascript-compat/lib/rule.test.js b/packages/eslint-plugin-ecmascript-compat/lib/rule.test.js index 3c757cd..8a34921 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/rule.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/rule.test.js @@ -1,7 +1,7 @@ -const assert = require('node:assert'); -const { test } = require('node:test'); -const features = require('./features'); -const rule = require('./rule'); +import assert from 'node:assert'; +import { test } from 'node:test'; +import features from './features/index.js'; +import rule from './rule.js'; test('polyfills accepted in the schema exactly match those supported', () => { const schemaPolyfills = rule.meta.schema[0].properties.polyfills.items.enum; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.js b/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.js index 1b9a215..bbfec57 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.js @@ -1,9 +1,10 @@ -const browserslist = require('browserslist'); -const _ = require('lodash'); -const compatData = require('@mdn/browser-compat-data'); -const compareVersions = require('./compareVersions'); +import browserslist from 'browserslist'; +import _ from 'lodash'; +// Import assertions aren't yet stage 4 so aren't supported by ESLint +import compatData from '@mdn/browser-compat-data/forLegacyNode'; +import compareVersions from './compareVersions.js'; -module.exports = function targetRuntimes(overrideBrowserslist, browserslistOptions) { +export default function targetRuntimes(overrideBrowserslist, browserslistOptions) { // ['chrome 50', ...] const allNamedVersions = browserslist(overrideBrowserslist, browserslistOptions); @@ -30,7 +31,7 @@ module.exports = function targetRuntimes(overrideBrowserslist, browserslistOptio // [ { name, version } ] return Object.entries(final).map(([name, version]) => ({ name, version })); -}; +} function isKnownFamily(name) { return compatData.browsers[name] != null; diff --git a/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.test.js b/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.test.js index f9dbe20..9da72fc 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.test.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.test.js @@ -1,7 +1,7 @@ -const assert = require('node:assert'); -const { beforeEach, it } = require('node:test'); -const browserslist = require('browserslist'); -const targetRuntimes = require('./targetRuntimes'); +import assert from 'node:assert'; +import { beforeEach, it } from 'node:test'; +import browserslist from 'browserslist'; +import targetRuntimes from './targetRuntimes.js'; beforeEach(() => { delete process.env.BROWSERSLIST; diff --git a/packages/eslint-plugin-ecmascript-compat/package.json b/packages/eslint-plugin-ecmascript-compat/package.json index 750a658..7e99a88 100644 --- a/packages/eslint-plugin-ecmascript-compat/package.json +++ b/packages/eslint-plugin-ecmascript-compat/package.json @@ -31,6 +31,7 @@ }, "license": "MIT", "author": "Robat Williams", + "type": "module", "main": "lib/index.js", "scripts": { "test": "node --test"