From b185f4dbe6450a22473fcc64c673d01683872742 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Fri, 5 May 2023 15:16:16 +0100 Subject: [PATCH] chore: use eslint plugin for preventing externals/builtins --- .eslintrc.local.js | 27 +++++++++++++++++++++++++++ .gitignore | 1 - package.json | 6 ++---- rollup.config.js | 22 ---------------------- test/map.js | 22 +++++++++++++++------- 5 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 .eslintrc.local.js delete mode 100644 rollup.config.js diff --git a/.eslintrc.local.js b/.eslintrc.local.js new file mode 100644 index 00000000..071d2379 --- /dev/null +++ b/.eslintrc.local.js @@ -0,0 +1,27 @@ +'use strict' + +module.exports = { + plugins: ['import'], + rules: { + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: false, + optionalDependencies: false, + peerDependencies: false, + bundledDependencies: false, + includeInternal: true, + }, + ], + 'import/no-nodejs-modules': ['error'], + }, + overrides: [ + { + files: ['**/test/**', '.eslintrc.js', '.eslintrc.local.js'], + rules: { + 'import/no-extraneous-dependencies': 0, + 'import/no-nodejs-modules': 0, + }, + }, + ], +} diff --git a/.gitignore b/.gitignore index 71430472..3b94e235 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,3 @@ !/SECURITY.md !/tap-snapshots/ !/test/ -!/rollup.config.js diff --git a/package.json b/package.json index 873f6bc3..f2c4963f 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,8 @@ "description": "The semantic version parser used by npm.", "main": "index.js", "scripts": { - "test": "tap && npm run check-self-contained", + "test": "tap", "snap": "tap", - "check-self-contained": "rollup -c --silent > /dev/null", "lint": "eslint \"**/*.js\"", "postlint": "template-oss-check", "lintfix": "npm run lint -- --fix", @@ -16,8 +15,7 @@ "devDependencies": { "@npmcli/eslint-config": "^4.0.0", "@npmcli/template-oss": "4.14.1", - "@rollup/plugin-commonjs": "^24.1.0", - "rollup": "^3.21.5", + "eslint-plugin-import": "^2.27.5", "tap": "^16.0.0" }, "license": "ISC", diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index e298738b..00000000 --- a/rollup.config.js +++ /dev/null @@ -1,22 +0,0 @@ -const fs = require('fs') -const commonjs = require('@rollup/plugin-commonjs') - -const pkgJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8')) - -module.exports = { - input: pkgJson.main, - plugins: [ - commonjs({ - strictRequires: true, - ignoreTryCatch: true, - }), - ], - external: Object.keys(pkgJson.dependencies), - onwarn: (e) => { - if (e.code === 'CIRCULAR_DEPENDENCY') { - return - } - - throw new Error(e) - }, -} diff --git a/test/map.js b/test/map.js index 52d5408f..397619b4 100644 --- a/test/map.js +++ b/test/map.js @@ -11,14 +11,19 @@ const ignore = [ 'tap-snapshots', 'test', 'fixtures', - 'rollup.config.js', ] const { statSync, readdirSync } = require('fs') const find = (folder, set = [], root = true) => { const ent = readdirSync(folder) - set.push(...ent.filter(f => !ignore.includes(f) && /\.m?js$/.test(f)).map(f => folder + '/' + f)) - for (const e of ent.filter(f => !ignore.includes(f) && !/\.m?js$/.test(f))) { + set.push( + ...ent + .filter((f) => !ignore.includes(f) && /\.m?js$/.test(f)) + .map((f) => folder + '/' + f) + ) + for (const e of ent.filter( + (f) => !ignore.includes(f) && !/\.m?js$/.test(f) + )) { if (statSync(folder + '/' + e).isDirectory()) { find(folder + '/' + e, set, false) } @@ -26,8 +31,8 @@ const find = (folder, set = [], root = true) => { if (!root) { return } - return set.map(f => f.slice(folder.length + 1) - .replace(/\\/g, '/')) + return set + .map((f) => f.slice(folder.length + 1).replace(/\\/g, '/')) .sort((a, b) => a.localeCompare(b)) } @@ -40,10 +45,13 @@ t.strictSame(sut, tests, 'test files should match system files') const map = require('../map.js') for (const testFile of tests) { - t.test(testFile, t => { + t.test(testFile, (t) => { t.plan(1) // cast to an array, since map() can return a string or array const systemFiles = [].concat(map(testFile)) - t.ok(systemFiles.some(sys => sut.includes(sys)), 'test covers a file') + t.ok( + systemFiles.some((sys) => sut.includes(sys)), + 'test covers a file' + ) }) }