Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

npx run-if-changed
run-if-changed
3 changes: 1 addition & 2 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

npx run-if-changed
run-if-changed
3 changes: 1 addition & 2 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

npx run-if-changed
run-if-changed
3 changes: 1 addition & 2 deletions .husky/post-rewrite
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

npx run-if-changed
run-if-changed
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

npx lint-staged
lint-staged
3 changes: 1 addition & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

npm test && npm run build && npm run check-docs
pnpm test && pnpm run build && pnpm run check-docs
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ can be ignored by being preceded by `/* c8 ignore next */` (including
for warnings where the block is never passed over (i.e., the block is always
entered)). If you want to test without coverage at all, you can use
`pnpm test-no-cov`. To only test rules rather than other files, you
can use `npm run test-index` (`pnpm` doesn't work with this script currently).
can use `pnpm run test-index`.

To test specific rules, you can supply a comma-separated list with the `--rule`
flag passed to `test-index`, e.g., for `check-examples` and `require-example`:

`npm run test-index --rule=check-examples,require-example`.
`pnpm run test-index --rule=check-examples,require-example`.

You can further limit this by providing `--invalid` and/or `--valid` flags
with a comma-separated list of 0-based indexes that you wish to include (also
accepts negative offsets from the end, e.g., `-1` for the last item). For
example, to check the first and third invalid tests of `check-examples`
along with the second valid test, you can run:

`npm run test-index --rule=require-example --invalid=0,2 --valid=1`.
`pnpm run test-index --rule=require-example --invalid=0,2 --valid=1`.

## Requirements for PRs

Expand Down
26 changes: 10 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"c8": "^10.1.3",
"camelcase": "^8.0.0",
"chai": "^5.2.0",
"cross-env": "^7.0.3",
"decamelize": "^6.0.0",
"eslint": "9.29.0",
"eslint-config-canonical": "~44.9.5",
Expand Down Expand Up @@ -80,11 +79,7 @@
],
"license": "BSD-3-Clause",
"lint-staged": {
".eslintignore": [
"npm run lint-fix",
"git add ."
],
"*.js": "npm run lint-arg -- --fix"
"*.js": "eslint --fix"
},
"type": "module",
"main": "./dist/index.cjs",
Expand Down Expand Up @@ -140,25 +135,24 @@
"url": "https://github.com/gajus/eslint-plugin-jsdoc/issues"
},
"run-if-changed": {
"package-lock.json": "npm run install-offline"
"package-lock.json": "pnpm run install-offline"
},
"scripts": {
"tsc": "tsc",
"tsc-build": "tsc -p tsconfig-prod.json",
"build": "rimraf ./dist && cross-env NODE_ENV=production babel ./src --out-file-extension .cjs --out-dir ./dist --copy-files --source-maps --ignore ./src/bin/*.js --no-copy-ignored && replace 'require\\(\"\\.(.*?)\\.[^.]*?\"\\)' 'require(\".$1.cjs\")' 'dist' -r --include=\"*.cjs\" && pnpm tsc-build",
"build": "rimraf ./dist && NODE_ENV=production babel ./src --out-file-extension .cjs --out-dir ./dist --copy-files --source-maps --ignore ./src/bin/*.js --no-copy-ignored && replace 'require\\(\"\\.(.*?)\\.[^.]*?\"\\)' 'require(\".$1.cjs\")' 'dist' -r --include=\"*.cjs\" && pnpm tsc-build",
"check-docs": "babel-node ./src/bin/generateDocs.js --check",
"create-docs": "npm run create-options && babel-node ./src/bin/generateDocs.js",
"create-docs": "pnpm run create-options && babel-node ./src/bin/generateDocs.js",
"create-rule": "babel-node ./src/bin/generateRule.js",
"create-options": "node ./src/bin/generateOptions.mjs",
"install-offline": "pnpm install --prefer-offline --no-audit",
"lint": "npm run lint-arg -- .",
"lint-arg": "eslint",
"lint-fix": "npm run lint-arg -- --fix .",
"lint": "eslint",
"lint-fix": "eslint --fix",
"prepare": "husky",
"test-no-cov": "cross-env BABEL_ENV=test mocha",
"test": "c8 npm run test-no-cov",
"test-cov": "cross-env TIMING=1 c8 --reporter text npm run test-no-cov",
"test-index": "npm run test-no-cov -- test/rules/index.js"
"test-no-cov": "BABEL_ENV=test mocha",
"test": "c8 pnpm run test-no-cov",
"test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
"test-index": "pnpm run test-no-cov test/rules/index.js"
},
"version": "1.0.0"
}
24 changes: 1 addition & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ignoredBuiltDependencies:
- core-js
- core-js-pure

shellEmulator: true
2 changes: 1 addition & 1 deletion src/bin/generateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const assertDocsAreUpToDate = async () => {
const isUpToDate = fs.readFileSync(docPath, 'utf8') === docContent;

if (!isUpToDate) {
throw new Error('Docs are not up to date, please run `npm run create-docs` to update it.');
throw new Error('Docs are not up to date, please run `pnpm run create-docs` to update it.');
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/bin/generateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @example
* ```shell
* npm run create-rule my-new-rule -- --recommended
* pnpm run create-rule my-new-rule -- --recommended
* ```
*/
import open from 'open-editor';
Expand All @@ -16,7 +16,7 @@
resolve,
} from 'path';

// Todo: Would ideally have prompts, e.g., to ask for whether

Check warning on line 19 in src/bin/generateRule.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'Todo: Would ideally have prompts, e.g.,...'
// type was problem/layout, etc.

const [
Expand Down
43 changes: 36 additions & 7 deletions test/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
readFileSync,
} from 'fs';
import defaultsDeep from 'lodash.defaultsdeep';
import {
parseArgs,
} from 'node:util';
import {
join,
} from 'path';
Expand All @@ -31,7 +34,33 @@ const main = async () => {
throw new Error('TypeScript guard');
}

for (const ruleName of process.env.npm_config_rule ? process.env.npm_config_rule.split(',') : ruleNames) {
/**
* @satisfies {import('node:util').ParseArgsOptionsConfig}
*/
const options = {
invalid: {
type: 'string',
},
rule: {
type: 'string',
},
valid: {
type: 'string',
},
};

const {
values: {
invalid,
rule: rules,
valid,
},
} = parseArgs({
allowPositionals: true,
options,
});

for (const ruleName of rules ? rules.split(/[, ]/v) : ruleNames) {
if (semver.gte(ESLint.version, '8.0.0') && ruleName === 'check-examples') {
// Uses the processor instead for higher versions
continue;
Expand Down Expand Up @@ -124,24 +153,24 @@ const main = async () => {
return assertion;
});

if (process.env.npm_config_invalid) {
const indexes = process.env.npm_config_invalid.split(',');
if (invalid) {
const indexes = invalid.split(/[, ]/v);
assertions.invalid = assertions.invalid.filter((_assertion, idx) => {
return indexes.includes(String(idx)) ||
indexes.includes(String(idx - assertions.invalid.length));
});
if (!process.env.npm_config_valid) {
if (!valid) {
assertions.valid = [];
}
}

if (process.env.npm_config_valid) {
const indexes = process.env.npm_config_valid.split(',');
if (valid) {
const indexes = valid.split(/[, ]/v);
assertions.valid = assertions.valid.filter((_assertion, idx) => {
return indexes.includes(String(idx)) ||
indexes.includes(String(idx - assertions.valid.length));
});
if (!process.env.npm_config_invalid) {
if (!invalid) {
assertions.invalid = [];
}
}
Expand Down
Loading