Skip to content

Commit

Permalink
chore: use eslint plugin for preventing externals/builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed May 5, 2023
1 parent d0a105e commit b185f4d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.local.js
Original file line number Diff line number Diff line change
@@ -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,
},
},
],
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@
!/SECURITY.md
!/tap-snapshots/
!/test/
!/rollup.config.js
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
22 changes: 0 additions & 22 deletions rollup.config.js

This file was deleted.

22 changes: 15 additions & 7 deletions test/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ 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)
}
}
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))
}

Expand All @@ -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'
)
})
}

0 comments on commit b185f4d

Please sign in to comment.