diff --git a/eslint.config.js b/eslint.config.js index d92f44345..2f88eb2e8 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -40,18 +40,6 @@ export default defineConfig([ "no-underscore-dangle": "off", }, }, - { - files: ["packages/eslint-scope/Makefile.js"], - languageOptions: { - globals: { - ...globals.shelljs, - target: false, - }, - }, - rules: { - "no-console": "off", - }, - }, { files: ["packages/eslint-scope/**"], linterOptions: { diff --git a/packages/eslint-scope/Makefile.js b/packages/eslint-scope/Makefile.js deleted file mode 100644 index e299a7746..000000000 --- a/packages/eslint-scope/Makefile.js +++ /dev/null @@ -1,131 +0,0 @@ -/** - * @fileoverview Build file - * @author nzakas - * @copyright OpenJS Foundation and other contributors, https://openjsf.org/ - * MIT License - */ - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -import path from "node:path"; -import { fileURLToPath } from "node:url"; - -import "shelljs/make.js"; -import checker from "npm-license"; - -const dirname = path.dirname(fileURLToPath(import.meta.url)); - -// `shelljs/make.js` global command to unset any `set('-e')` (to exit upon -// first error) -set("+e"); - -//------------------------------------------------------------------------------ -// Settings -//------------------------------------------------------------------------------ - -const OPEN_SOURCE_LICENSES = [ - /MIT/u, - /BSD/u, - /Apache/u, - /ISC/u, - /WTF/u, - /Public Domain/u, -]; - -//------------------------------------------------------------------------------ -// Data -//------------------------------------------------------------------------------ - -const NODE = "node", - NODE_MODULES = "../../node_modules", - // Utilities - intentional extra space at the end of each string - MOCHA = `${NODE_MODULES}/mocha/bin/_mocha `, - // If switching back to Istanbul when may be working with ESM - // ISTANBUL = `${NODE} ${NODE_MODULES}/istanbul/lib/cli.js `, - C8 = `${NODE} ${NODE_MODULES}/c8/bin/c8.js`, - // Files - TEST_FILES = "tests/**/*.test.js", - CJS_TEST_FILES = "tests/**/*.test.cjs"; - -//------------------------------------------------------------------------------ -// Tasks -//------------------------------------------------------------------------------ - -target.all = function () { - target.test(); -}; - -target.test = function () { - let errors = 0; - let lastReturn = exec( - `${NODE} ${MOCHA} -- -R progress -c ${CJS_TEST_FILES}`, - ); - - if (lastReturn.code !== 0) { - errors++; - } - - lastReturn = exec(`${C8} ${MOCHA} -- -R progress -c ${TEST_FILES}`); - - if (lastReturn.code !== 0) { - errors++; - } - - if (errors) { - exit(1); - } - - target.checkLicenses(); -}; - -target.checkLicenses = function () { - /** - * Returns true if the given dependency's licenses are all permissable for use in OSS - * @param {Object} dependency object containing the name and licenses of the given dependency - * @returns {boolean} is permissable dependency - */ - function isPermissible(dependency) { - const licenses = dependency.licenses; - - if (Array.isArray(licenses)) { - return licenses.some(license => - isPermissible({ - name: dependency.name, - licenses: license, - }), - ); - } - - return OPEN_SOURCE_LICENSES.some(license => license.test(licenses)); - } - - echo("Validating licenses"); - - checker.init( - { - start: dirname, - meta: "./licenses-meta-data.json", - }, - deps => { - const impermissible = Object.keys(deps) - .map(dependency => ({ - name: dependency, - licenses: deps[dependency].licenses, - })) - .filter(dependency => !isPermissible(dependency)); - - if (impermissible.length) { - impermissible.forEach(dependency => { - console.error( - "%s license for %s is impermissible.", - dependency.licenses, - dependency.name, - ); - }); - exit(1); - } - }, - ); -}; diff --git a/packages/eslint-scope/package.json b/packages/eslint-scope/package.json index 590a0b331..561ea77bc 100644 --- a/packages/eslint-scope/package.json +++ b/packages/eslint-scope/package.json @@ -39,9 +39,11 @@ "build": "rollup -c", "lint:types": "attw --pack", "pretest": "npm run build", - "test": "npm run test:types && npm run test:unit", + "test": "npm run test:types && npm run test:unit && npm run test:licenses", + "test:coverage": "c8 npm run test:unit", + "test:licenses": "node tools/check-licenses.js", "test:types": "tsc -p tsconfig.json && tsc -p tests/types/tsconfig.json", - "test:unit": "node Makefile.js test" + "test:unit": "mocha \"tests/**/*.test.{js,cjs}\"" }, "files": [ "LICENSE", @@ -61,7 +63,6 @@ "eslint": "^10.4.0", "eslint-visitor-keys": "^5.0.1", "espree": "^11.2.0", - "npm-license": "^0.3.3", - "shelljs": "^0.10.0" + "npm-license": "^0.3.3" } } diff --git a/packages/eslint-scope/tools/check-licenses.js b/packages/eslint-scope/tools/check-licenses.js new file mode 100644 index 000000000..e089d1dd5 --- /dev/null +++ b/packages/eslint-scope/tools/check-licenses.js @@ -0,0 +1,80 @@ +/** + * @fileoverview Build file + * @author nzakas + * @copyright OpenJS Foundation and other contributors, https://openjsf.org/ + * MIT License + */ + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +import { fileURLToPath } from "node:url"; +import checker from "npm-license"; + +//------------------------------------------------------------------------------ +// Settings +//------------------------------------------------------------------------------ + +const OPEN_SOURCE_LICENSES = [ + /MIT/u, + /BSD/u, + /Apache/u, + /ISC/u, + /WTF/u, + /Public Domain/u, +]; + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Returns true if the given dependency's licenses are all permissable for use in OSS + * @param {Object} dependency object containing the name and licenses of the given dependency + * @returns {boolean} is permissable dependency + */ +function isPermissible(dependency) { + const licenses = dependency.licenses; + + if (Array.isArray(licenses)) { + return licenses.some(license => + isPermissible({ + name: dependency.name, + licenses: license, + }), + ); + } + + return OPEN_SOURCE_LICENSES.some(license => license.test(licenses)); +} + +//------------------------------------------------------------------------------ +// License Checking +//------------------------------------------------------------------------------ + +checker.init( + { + start: fileURLToPath(new URL("..", import.meta.url)), + meta: "./tools/licenses-meta-data.json", + }, + deps => { + const impermissible = Object.keys(deps) + .map(dependency => ({ + name: dependency, + licenses: deps[dependency].licenses, + })) + .filter(dependency => !isPermissible(dependency)); + + if (impermissible.length) { + impermissible.forEach(dependency => { + console.error( + "%s license for %s is impermissible.", + dependency.licenses, + dependency.name, + ); + }); + process.exitCode = 1; + } + }, +); diff --git a/packages/eslint-scope/licenses-meta-data.json b/packages/eslint-scope/tools/licenses-meta-data.json similarity index 100% rename from packages/eslint-scope/licenses-meta-data.json rename to packages/eslint-scope/tools/licenses-meta-data.json diff --git a/packages/eslint-visitor-keys/README.md b/packages/eslint-visitor-keys/README.md index 5e8137f31..f2258f37c 100644 --- a/packages/eslint-visitor-keys/README.md +++ b/packages/eslint-visitor-keys/README.md @@ -96,7 +96,7 @@ Welcome. See [ESLint contribution guidelines](https://eslint.org/docs/latest/con ### Development commands -- `npm test` runs tests and measures code coverage. +- `npm test` runs tests. - `npm run lint` checks source codes with ESLint. - `npm run test:coverage` runs tests and generates code coverage report. diff --git a/packages/eslint-visitor-keys/package.json b/packages/eslint-visitor-keys/package.json index 31c05ef43..ff01546dd 100644 --- a/packages/eslint-visitor-keys/package.json +++ b/packages/eslint-visitor-keys/package.json @@ -35,7 +35,7 @@ "test": "npm run test:types && npm run test:unit", "test:coverage": "c8 npm run test:unit", "test:types": "tsd", - "test:unit": "mocha \"tests/**/*.test.cjs\" && mocha \"tests/**/*.test.js\"" + "test:unit": "mocha \"tests/**/*.test.{js,cjs}\"" }, "repository": { "type": "git", diff --git a/packages/espree/package.json b/packages/espree/package.json index 9d68e6ce8..ac28d8311 100644 --- a/packages/espree/package.json +++ b/packages/espree/package.json @@ -63,10 +63,9 @@ "lint:types": "attw --pack", "pretest": "npm run build", "test": "npm run test:types && npm run test:unit", - "test:cjs": "mocha --color --reporter progress --timeout 30000 \"tests/**/*.test.cjs\"", - "test:esm": "c8 mocha --color --reporter progress --timeout 30000 \"tests/**/*.test.js\"", + "test:coverage": "c8 npm run test:unit", "test:types": "tsd --typings dist/espree.d.ts", - "test:unit": "npm run test:cjs && npm run test:esm" + "test:unit": "mocha \"tests/**/*.test.{js,cjs}\"" }, "sideEffects": false }