Skip to content

Commit 1dc3e29

Browse files
lishaduckbrettz9
authored andcommitted
fix: test-index should use parseArgs instead
1 parent 1f39472 commit 1dc3e29

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
],
8080
"license": "BSD-3-Clause",
8181
"lint-staged": {
82-
"*.js": "pnpm run lint-arg --fix"
82+
"*.js": "eslint --fix"
8383
},
8484
"type": "module",
8585
"main": "./dist/index.cjs",
@@ -146,14 +146,13 @@
146146
"create-rule": "babel-node ./src/bin/generateRule.js",
147147
"create-options": "node ./src/bin/generateOptions.mjs",
148148
"install-offline": "pnpm install --prefer-offline --no-audit",
149-
"lint": "pnpm run lint-arg -- .",
150-
"lint-arg": "eslint",
151-
"lint-fix": "pnpm run lint-arg --fix .",
149+
"lint": "eslint",
150+
"lint-fix": "eslint --fix",
152151
"prepare": "husky",
153152
"test-no-cov": "BABEL_ENV=test mocha",
154153
"test": "c8 pnpm run test-no-cov",
155154
"test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
156-
"test-index": "pnpm run test-no-cov -- test/rules/index.js"
155+
"test-index": "pnpm run test-no-cov test/rules/index.js"
157156
},
158157
"version": "1.0.0"
159158
}

test/rules/index.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
readFileSync,
99
} from 'fs';
1010
import defaultsDeep from 'lodash.defaultsdeep';
11+
import {
12+
parseArgs,
13+
} from 'node:util';
1114
import {
1215
join,
1316
} from 'path';
@@ -31,7 +34,33 @@ const main = async () => {
3134
throw new Error('TypeScript guard');
3235
}
3336

34-
for (const ruleName of process.env.npm_config_rule ? process.env.npm_config_rule.split(',') : ruleNames) {
37+
/**
38+
* @satisfies {import('node:util').ParseArgsOptionsConfig}
39+
*/
40+
const options = {
41+
invalid: {
42+
type: 'string',
43+
},
44+
rule: {
45+
type: 'string',
46+
},
47+
valid: {
48+
type: 'string',
49+
},
50+
};
51+
52+
const {
53+
values: {
54+
invalid,
55+
rule: rules,
56+
valid,
57+
},
58+
} = parseArgs({
59+
allowPositionals: true,
60+
options,
61+
});
62+
63+
for (const ruleName of rules ? rules.split(/[, ]/v) : ruleNames) {
3564
if (semver.gte(ESLint.version, '8.0.0') && ruleName === 'check-examples') {
3665
// Uses the processor instead for higher versions
3766
continue;
@@ -124,24 +153,24 @@ const main = async () => {
124153
return assertion;
125154
});
126155

127-
if (process.env.npm_config_invalid) {
128-
const indexes = process.env.npm_config_invalid.split(',');
156+
if (invalid) {
157+
const indexes = invalid.split(/[, ]/v);
129158
assertions.invalid = assertions.invalid.filter((_assertion, idx) => {
130159
return indexes.includes(String(idx)) ||
131160
indexes.includes(String(idx - assertions.invalid.length));
132161
});
133-
if (!process.env.npm_config_valid) {
162+
if (!valid) {
134163
assertions.valid = [];
135164
}
136165
}
137166

138-
if (process.env.npm_config_valid) {
139-
const indexes = process.env.npm_config_valid.split(',');
167+
if (valid) {
168+
const indexes = valid.split(/[, ]/v);
140169
assertions.valid = assertions.valid.filter((_assertion, idx) => {
141170
return indexes.includes(String(idx)) ||
142171
indexes.includes(String(idx - assertions.valid.length));
143172
});
144-
if (!process.env.npm_config_invalid) {
173+
if (!invalid) {
145174
assertions.invalid = [];
146175
}
147176
}

0 commit comments

Comments
 (0)