Skip to content

Commit 805b54c

Browse files
fix: path ignored (#312)
* fix: path ignored * style: formatting * chore: update cspell * style: formatting
1 parent f73c4ba commit 805b54c

File tree

19 files changed

+77
-38
lines changed

19 files changed

+77
-38
lines changed

.cspell.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
"ignorePaths": [
2020
"CHANGELOG.md",
2121
"package.json",
22+
"coverage/**",
2223
"dist/**",
2324
"**/__snapshots__/**",
24-
"package-lock.json"
25+
"package-lock.json",
26+
"/test/output"
2527
]
2628
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Dependency Review"
1+
name: 'Dependency Review'
22
on: [pull_request]
33

44
permissions:
@@ -8,7 +8,7 @@ jobs:
88
dependency-review:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: "Checkout Repository"
11+
- name: 'Checkout Repository'
1212
uses: actions/checkout@v3
13-
- name: "Dependency Review"
13+
- name: 'Dependency Review'
1414
uses: actions/dependency-review-action@v3

src/getStylelint.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const cache = {};
1313
/** @typedef {import('stylelint')} Stylelint */
1414
/** @typedef {import('stylelint').LintResult} LintResult */
1515
/** @typedef {import('./options').Options} Options */
16+
/** @typedef {(stylelint: Stylelint, filePath: string) => Promise<boolean>} isPathIgnored */
1617
/** @typedef {() => Promise<void>} AsyncTask */
1718
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
18-
/** @typedef {{api: import('stylelint').InternalApi, stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
19+
/** @typedef {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lintFiles: LintTask, cleanup: AsyncTask, threads: number }} Linter */
1920
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
2021

2122
/**
@@ -26,9 +27,23 @@ function loadStylelint(options) {
2627
const stylelintOptions = getStylelintOptions(options);
2728
const stylelint = setup(options, stylelintOptions);
2829

30+
/** @type {isPathIgnored} */
31+
let isPathIgnored;
32+
33+
try {
34+
isPathIgnored = require(`${options.stylelintPath}/lib/isPathIgnored`);
35+
} catch (e) {
36+
try {
37+
// @ts-ignore
38+
isPathIgnored = require('stylelint/lib/isPathIgnored');
39+
} catch (_) {
40+
isPathIgnored = () => Promise.resolve(false);
41+
}
42+
}
43+
2944
return {
3045
stylelint,
31-
api: stylelint.createLinter(stylelintOptions),
46+
isPathIgnored,
3247
lintFiles,
3348
cleanup: async () => {},
3449
threads: 1,

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ class StylelintWebpackPlugin {
9090
}
9191

9292
compiler.hooks.thisCompilation.tap(this.key, (compilation) => {
93+
/** @type {import('stylelint')} */
94+
let stylelint;
95+
9396
/** @type {import('./linter').Linter} */
9497
let lint;
9598

96-
/** @type {import('stylelint').InternalApi} */
97-
let api;
99+
/** @type {import('./linter').isPathIgnored} */
100+
let isPathIgnored;
98101

99102
/** @type {import('./linter').Reporter} */
100103
let report;
@@ -103,7 +106,7 @@ class StylelintWebpackPlugin {
103106
let threads;
104107

105108
try {
106-
({ lint, api, report, threads } = linter(
109+
({ stylelint, lint, isPathIgnored, report, threads } = linter(
107110
this.key,
108111
options,
109112
compilation
@@ -127,7 +130,7 @@ class StylelintWebpackPlugin {
127130
: globby.sync(wanted, { dot: true, ignore: exclude })
128131
).map(async (file) => {
129132
try {
130-
return (await api.isPathIgnored(file)) ? false : file;
133+
return (await isPathIgnored(stylelint, file)) ? false : file;
131134
} catch (e) {
132135
return file;
133136
}

src/linter.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const { arrify } = require('./utils');
77
/** @typedef {import('stylelint')} Stylelint */
88
/** @typedef {import('stylelint').LintResult} LintResult */
99
/** @typedef {import('stylelint').LinterResult} LinterResult */
10-
/** @typedef {import('stylelint').InternalApi} InternalApi */
1110
/** @typedef {import('stylelint').Formatter} Formatter */
1211
/** @typedef {import('stylelint').FormatterType} FormatterType */
1312
/** @typedef {import('webpack').Compiler} Compiler */
1413
/** @typedef {import('webpack').Compilation} Compilation */
1514
/** @typedef {import('./options').Options} Options */
15+
/** @typedef {import('./getStylelint').isPathIgnored} isPathIgnored */
1616
/** @typedef {(compilation: Compilation) => Promise<void>} GenerateReport */
1717
/** @typedef {{errors?: StylelintError, warnings?: StylelintError, generateReportAsset?: GenerateReport}} Report */
1818
/** @typedef {() => Promise<Report>} Reporter */
@@ -26,14 +26,14 @@ const resultStorage = new WeakMap();
2626
* @param {string|undefined} key
2727
* @param {Options} options
2828
* @param {Compilation} compilation
29-
* @returns {{api: InternalApi, lint: Linter, report: Reporter, threads: number}}
29+
* @returns {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lint: Linter, report: Reporter, threads: number}}
3030
*/
3131
function linter(key, options, compilation) {
3232
/** @type {Stylelint} */
3333
let stylelint;
3434

35-
/** @type {InternalApi} */
36-
let api;
35+
/** @type {isPathIgnored} */
36+
let isPathIgnored;
3737

3838
/** @type {(files: string|string[]) => Promise<LintResult[]>} */
3939
let lintFiles;
@@ -50,7 +50,7 @@ function linter(key, options, compilation) {
5050
const crossRunResultStorage = getResultStorage(compilation);
5151

5252
try {
53-
({ stylelint, api, lintFiles, cleanup, threads } = getStylelint(
53+
({ stylelint, isPathIgnored, lintFiles, cleanup, threads } = getStylelint(
5454
key,
5555
options
5656
));
@@ -59,8 +59,9 @@ function linter(key, options, compilation) {
5959
}
6060

6161
return {
62+
stylelint,
6263
lint,
63-
api,
64+
isPathIgnored,
6465
report,
6566
threads,
6667
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
display: block;
3+
}

0 commit comments

Comments
 (0)