Skip to content

Commit

Permalink
chore: Introduce Knip (#18005)
Browse files Browse the repository at this point in the history
* chore: add Knip + config

* chore: use named exports consistently (only shorthands)

* chore: update Knip & reduce config (by improved 11ty plugin)

* chore: rename `lint:knip` → `lint:imports`

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>

* chore: upgrade Knip to v4.3.0

* chore: fix createCoreRuleConfigs import in test

* chore: annotate default export for runtime-info (to satisfy both proxyquire and knip)

* chore: update knip.jsonc

Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>

* chore: add comment to export/import hint

* chore: upgrade Knip to v5.0.1 (no breaking changes)

* chore: remove unused files, dependencies & exports

* chore: fix whitespace in ci.yml

* chore: add Knip to CI job

* Remove tools/update-rule-types.js from knip.jsonc

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Add corrected shared/types Rule import to lazy-loading-rule-map.js

* Added back eslint-plugin-* devDependencies

* Rename to lint:unused

* Fix introduced prism-eslint-hook complaints

---------

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
4 people committed Mar 11, 2024
1 parent ba89c73 commit acc2e06
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 308 deletions.
100 changes: 51 additions & 49 deletions .github/workflows/ci.yml
Expand Up @@ -13,32 +13,34 @@ jobs:
name: Verify Files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install Packages
run: npm install --force
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install Packages
run: npm install --force

- name: Install Docs Packages
working-directory: docs
run: npm install
- name: Install Docs Packages
working-directory: docs
run: npm install

- name: Lint Files
run: node Makefile lint
- name: Lint Files
run: node Makefile lint

- name: Check Rule Files
run: node Makefile checkRuleFiles
- name: Check Rule Files
run: node Makefile checkRuleFiles

- name: Check Licenses
run: node Makefile checkLicenses
- name: Check Licenses
run: node Makefile checkLicenses

- name: Lint Docs JS Files
run: node Makefile lintDocsJS
- name: Lint Docs JS Files
run: node Makefile lintDocsJS

- name: Check Rule Examples
run: node Makefile checkRuleExamples
- name: Check Rule Examples
run: node Makefile checkRuleExamples

- name: Lint Files, Dependencies, & Exports
run: npm run lint:unused

test_on_node:
name: Test
Expand All @@ -47,40 +49,40 @@ jobs:
os: [ubuntu-latest]
node: [21.x, 20.x, 18.x, "18.18.0"]
include:
- os: windows-latest
node: "lts/*"
- os: macOS-latest
node: "lts/*"
- os: windows-latest
node: "lts/*"
- os: macOS-latest
node: "lts/*"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install Packages
run: npm install --force
- name: Test
run: node Makefile mocha
- name: Fuzz Test
run: node Makefile fuzz
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install Packages
run: npm install --force
- name: Test
run: node Makefile mocha
- name: Fuzz Test
run: node Makefile fuzz

test_on_browser:
name: Browser Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20' # Should be the same as the version used on Netlify to build the ESLint Playground
- name: Install Packages
run: npm install --force
- name: Test
run: node Makefile wdio
- name: Fuzz Test
run: node Makefile fuzz
- uses: actions/upload-artifact@v3
if: failure()
with:
name: logs
path: |
wdio-logs/*.log
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20" # Should be the same as the version used on Netlify to build the ESLint Playground
- name: Install Packages
run: npm install --force
- name: Test
run: node Makefile wdio
- name: Fuzz Test
run: node Makefile fuzz
- uses: actions/upload-artifact@v3
if: failure()
with:
name: logs
path: |
wdio-logs/*.log
4 changes: 2 additions & 2 deletions Makefile.js
Expand Up @@ -532,8 +532,8 @@ target.lintDocsJS = function([fix = false] = []) {
};

target.fuzz = function({ amount = 1000, fuzzBrokenAutofixes = false } = {}) {
const fuzzerRunner = require("./tools/fuzzer-runner");
const fuzzResults = fuzzerRunner.run({ amount, fuzzBrokenAutofixes });
const { run } = require("./tools/fuzzer-runner");
const fuzzResults = run({ amount, fuzzBrokenAutofixes });

if (fuzzResults.length) {

Expand Down
3 changes: 2 additions & 1 deletion bin/eslint.js
Expand Up @@ -149,7 +149,8 @@ ${getErrorMessage(error)}`;
}

// Otherwise, call the CLI.
const exitCode = await require("../lib/cli").execute(
const cli = require("../lib/cli");
const exitCode = await cli.execute(
process.argv,
process.argv.includes("--stdin") ? await readStdin() : null,
true
Expand Down
4 changes: 2 additions & 2 deletions docs/.eleventy.js
Expand Up @@ -16,7 +16,7 @@ const {
} = require("luxon");
const markdownIt = require("markdown-it");
const markdownItRuleExample = require("./tools/markdown-it-rule-example");
const { addContentMustBeMarked } = require("./tools/prism-eslint-hook");
const prismESLintHook = require("./tools/prism-eslint-hook");

module.exports = function(eleventyConfig) {

Expand Down Expand Up @@ -197,7 +197,7 @@ module.exports = function(eleventyConfig) {
const ruleExampleOptions = markdownItRuleExample({
open({ type, code, parserOptions, env, codeBlockToken }) {

addContentMustBeMarked(codeBlockToken.content, parserOptions);
prismESLintHook.addContentMustBeMarked(codeBlockToken.content, parserOptions);

const isRuleRemoved = !Object.hasOwn(env.rules_meta, env.title);

Expand Down
5 changes: 0 additions & 5 deletions docs/package.json
Expand Up @@ -35,20 +35,15 @@
"autoprefixer": "^10.4.13",
"cross-env": "^7.0.3",
"cssnano": "^5.1.14",
"dom-parser": "^0.1.6",
"eleventy-plugin-nesting-toc": "^1.3.0",
"eleventy-plugin-page-assets": "^0.3.0",
"eleventy-plugin-reading-time": "^0.0.1",
"github-slugger": "^1.5.0",
"hyperlink": "^5.0.4",
"imagemin": "^8.0.1",
"imagemin-cli": "^7.0.0",
"js-yaml": "^3.14.1",
"luxon": "^2.4.0",
"markdown-it": "^12.2.0",
"markdown-it-anchor": "^8.1.2",
"markdown-it-container": "^3.0.0",
"netlify-cli": "^10.3.1",
"npm-run-all2": "^5.0.0",
"postcss-cli": "^10.0.0",
"postcss-html": "^1.5.0",
Expand Down
4 changes: 3 additions & 1 deletion docs/src/_plugins/md-syntax-highlighter.js
Expand Up @@ -26,7 +26,9 @@ SOFTWARE.

const Prism = require("prismjs");
const loadLanguages = require("prismjs/components/");
require("../../tools/prism-eslint-hook").installPrismESLintMarkerHook();
const prismESLintHook = require("../../tools/prism-eslint-hook");

prismESLintHook.installPrismESLintMarkerHook();

/**
*
Expand Down
52 changes: 52 additions & 0 deletions knip.jsonc
@@ -0,0 +1,52 @@
{
"workspaces": {
".": {
// These entries are complementary to the ones found in package.json
"entry": [
"lib/rules/index.js",
"tools/internal-rules/index.js",
// https://github.com/webpro/knip/issues/464
// Remove when Knip has a wdio plugin
"wdio.conf.js"
],
"project": ["{conf,lib,tools}/**/*.js"],
"mocha": {
"entry": [
"tests/{bin,conf,lib,tools}/**/*.js", // see Makefile.js
"tests/_utils/test-lazy-loading-rules.js"
],
"project": ["tests/**/*.js"]
},
"ignore": [
// If Knip would consider exports as named, their usage is too dynamic: globals[`es${ecmaVersion}`]
// An alternative is to add `__esModule: true` to the export and we can remove it here from the ignores:
"conf/globals.js",
// These contain unresolved imports and other oddities:
"tests/bench/large.js",
"tests/lib/rule-tester/rule-tester.js",
"tests/performance/jshint.js",
// Many are required using dynamic paths such as `fs.readFileSync(path.join())`:
"tests/fixtures/**"
],
"ignoreDependencies": [
"c8",

// These will be removed in https://github.com/eslint/eslint/pull/18011
"eslint-plugin-eslint-comments",
"eslint-plugin-jsdoc",
"eslint-plugin-n",
"eslint-plugin-unicorn",

// Ignore until Knip has a wdio plugin:
"@wdio/*",
"rollup-plugin-node-polyfills"
]
},
"docs": {
"ignore": ["src/assets/js/search.js", "_examples/**"]
},
// Workspaces with default configs:
"packages/*": {},
"tools/internal-rules": {}
}
}
34 changes: 0 additions & 34 deletions lib/cli-engine/xml-escape.js

This file was deleted.

3 changes: 1 addition & 2 deletions lib/config/flat-config-schema.js
Expand Up @@ -588,6 +588,5 @@ const flatConfigSchema = {

module.exports = {
flatConfigSchema,
assertIsRuleSeverity,
assertIsRuleOptions
assertIsRuleSeverity
};
1 change: 0 additions & 1 deletion lib/eslint/eslint-helpers.js
Expand Up @@ -907,7 +907,6 @@ function getCacheFile(cacheFile, cwd) {
//-----------------------------------------------------------------------------

module.exports = {
isGlobPattern,
findFiles,

isNonEmptyString,
Expand Down
4 changes: 1 addition & 3 deletions lib/linter/index.js
@@ -1,13 +1,11 @@
"use strict";

const { Linter } = require("./linter");
const { interpolate } = require("./interpolate");
const SourceCodeFixer = require("./source-code-fixer");

module.exports = {
Linter,

// For testers.
SourceCodeFixer,
interpolate
SourceCodeFixer
};
2 changes: 0 additions & 2 deletions lib/linter/linter.js
Expand Up @@ -58,8 +58,6 @@ const { LATEST_ECMA_VERSION } = require("../../conf/ecma-version");
// Typedefs
//------------------------------------------------------------------------------

/** @typedef {InstanceType<import("../cli-engine/config-array").ConfigArray>} ConfigArray */
/** @typedef {InstanceType<import("../cli-engine/config-array").ExtractedConfig>} ExtractedConfig */
/** @typedef {import("../shared/types").ConfigData} ConfigData */
/** @typedef {import("../shared/types").Environment} Environment */
/** @typedef {import("../shared/types").GlobalConf} GlobalConf */
Expand Down
4 changes: 3 additions & 1 deletion lib/rule-tester/index.js
@@ -1,5 +1,7 @@
"use strict";

const RuleTester = require("./rule-tester");

module.exports = {
RuleTester: require("./rule-tester")
RuleTester
};
2 changes: 1 addition & 1 deletion lib/rules/utils/lazy-loading-rule-map.js
Expand Up @@ -6,7 +6,7 @@

const debug = require("debug")("eslint:rules");

/** @typedef {import("./types").Rule} Rule */
/** @typedef {import("../../shared/types").Rule} Rule */

/**
* The `Map` object that loads each rule when it's accessed.
Expand Down
13 changes: 9 additions & 4 deletions lib/rules/utils/unicode/index.js
Expand Up @@ -3,9 +3,14 @@
*/
"use strict";

const isCombiningCharacter = require("./is-combining-character");
const isEmojiModifier = require("./is-emoji-modifier");
const isRegionalIndicatorSymbol = require("./is-regional-indicator-symbol");
const isSurrogatePair = require("./is-surrogate-pair");

module.exports = {
isCombiningCharacter: require("./is-combining-character"),
isEmojiModifier: require("./is-emoji-modifier"),
isRegionalIndicatorSymbol: require("./is-regional-indicator-symbol"),
isSurrogatePair: require("./is-surrogate-pair")
isCombiningCharacter,
isEmojiModifier,
isRegionalIndicatorSymbol,
isSurrogatePair
};

0 comments on commit acc2e06

Please sign in to comment.