@code-pushup/eslint-plugin 0.23.1 → 0.25.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +25 -19
- package/index.js +33 -18
- package/package.json +1 -1
- package/src/lib/config.d.ts +5 -0
- package/src/lib/runner/index.d.ts +3 -2
package/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/plugin-eslint/src/lib/runner/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join as join2 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// packages/models/src/lib/audit.ts
|
|
@@ -577,6 +577,17 @@ async function readJsonFile(path) {
|
|
|
577
577
|
const text = await readTextFile(path);
|
|
578
578
|
return JSON.parse(text);
|
|
579
579
|
}
|
|
580
|
+
async function ensureDirectoryExists(baseDir) {
|
|
581
|
+
try {
|
|
582
|
+
await mkdir(baseDir, { recursive: true });
|
|
583
|
+
return;
|
|
584
|
+
} catch (error) {
|
|
585
|
+
console.error(error.message);
|
|
586
|
+
if (error.code !== "EEXIST") {
|
|
587
|
+
throw error;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
580
591
|
function pluginWorkDir(slug) {
|
|
581
592
|
return join("node_modules", ".code-pushup", slug);
|
|
582
593
|
}
|
|
@@ -591,6 +602,9 @@ function compareIssueSeverity(severity1, severity2) {
|
|
|
591
602
|
return levels[severity1] - levels[severity2];
|
|
592
603
|
}
|
|
593
604
|
|
|
605
|
+
// packages/utils/src/lib/git.ts
|
|
606
|
+
import { simpleGit } from "simple-git";
|
|
607
|
+
|
|
594
608
|
// packages/utils/src/lib/transform.ts
|
|
595
609
|
function toArray(val) {
|
|
596
610
|
return Array.isArray(val) ? val : [val];
|
|
@@ -608,9 +622,6 @@ function distinct(array) {
|
|
|
608
622
|
return [...new Set(array)];
|
|
609
623
|
}
|
|
610
624
|
|
|
611
|
-
// packages/utils/src/lib/git.ts
|
|
612
|
-
import { simpleGit } from "simple-git";
|
|
613
|
-
|
|
614
625
|
// packages/utils/src/lib/logging.ts
|
|
615
626
|
import chalk2 from "chalk";
|
|
616
627
|
|
|
@@ -749,25 +760,20 @@ function convertSeverity(severity) {
|
|
|
749
760
|
var WORKDIR = pluginWorkDir("eslint");
|
|
750
761
|
var RUNNER_OUTPUT_PATH = join2(WORKDIR, "runner-output.json");
|
|
751
762
|
var ESLINTRC_PATH = join2(process.cwd(), WORKDIR, ".eslintrc.json");
|
|
752
|
-
var
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
throw new Error("Invalid runner args - missing eslintrc argument");
|
|
760
|
-
}
|
|
761
|
-
if (patterns.length === 0) {
|
|
762
|
-
throw new Error("Invalid runner args - missing patterns argument");
|
|
763
|
-
}
|
|
763
|
+
var PLUGIN_CONFIG_PATH = join2(
|
|
764
|
+
process.cwd(),
|
|
765
|
+
WORKDIR,
|
|
766
|
+
"plugin-config.json"
|
|
767
|
+
);
|
|
768
|
+
async function executeRunner() {
|
|
769
|
+
const { slugs, eslintrc, patterns } = await readJsonFile(PLUGIN_CONFIG_PATH);
|
|
764
770
|
const lintResults = await lint({
|
|
765
771
|
// if file created from inline object, provide inline to preserve relative links
|
|
766
772
|
eslintrc: eslintrc === ESLINTRC_PATH ? await readJsonFile(eslintrc) : eslintrc,
|
|
767
773
|
patterns
|
|
768
774
|
});
|
|
769
775
|
const failedAudits = lintResultsToAudits(lintResults);
|
|
770
|
-
const audits = slugs.
|
|
776
|
+
const audits = slugs.map(
|
|
771
777
|
(slug) => failedAudits.find((audit) => audit.slug === slug) ?? {
|
|
772
778
|
slug,
|
|
773
779
|
score: 1,
|
|
@@ -776,9 +782,9 @@ async function executeRunner(argv = process.argv) {
|
|
|
776
782
|
details: { issues: [] }
|
|
777
783
|
}
|
|
778
784
|
);
|
|
779
|
-
await
|
|
785
|
+
await ensureDirectoryExists(dirname(RUNNER_OUTPUT_PATH));
|
|
780
786
|
await writeFile(RUNNER_OUTPUT_PATH, JSON.stringify(audits));
|
|
781
787
|
}
|
|
782
788
|
|
|
783
789
|
// packages/plugin-eslint/src/bin.ts
|
|
784
|
-
await executeRunner()
|
|
790
|
+
await executeRunner();
|
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// packages/plugin-eslint/src/lib/eslint-plugin.ts
|
|
2
|
-
import { mkdir as mkdir2, writeFile } from "node:fs/promises";
|
|
2
|
+
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
3
3
|
import { dirname as dirname2, join as join3 } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
// packages/plugin-eslint/package.json
|
|
7
7
|
var name = "@code-pushup/eslint-plugin";
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.25.6";
|
|
9
9
|
|
|
10
10
|
// packages/plugin-eslint/src/lib/config.ts
|
|
11
11
|
import { z } from "zod";
|
|
@@ -590,10 +590,24 @@ async function fileExists(path) {
|
|
|
590
590
|
return false;
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
|
+
async function ensureDirectoryExists(baseDir) {
|
|
594
|
+
try {
|
|
595
|
+
await mkdir(baseDir, { recursive: true });
|
|
596
|
+
return;
|
|
597
|
+
} catch (error) {
|
|
598
|
+
console.error(error.message);
|
|
599
|
+
if (error.code !== "EEXIST") {
|
|
600
|
+
throw error;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
593
604
|
function pluginWorkDir(slug) {
|
|
594
605
|
return join("node_modules", ".code-pushup", slug);
|
|
595
606
|
}
|
|
596
607
|
|
|
608
|
+
// packages/utils/src/lib/git.ts
|
|
609
|
+
import { simpleGit } from "simple-git";
|
|
610
|
+
|
|
597
611
|
// packages/utils/src/lib/transform.ts
|
|
598
612
|
function toArray(val) {
|
|
599
613
|
return Array.isArray(val) ? val : [val];
|
|
@@ -605,9 +619,6 @@ function distinct(array) {
|
|
|
605
619
|
return [...new Set(array)];
|
|
606
620
|
}
|
|
607
621
|
|
|
608
|
-
// packages/utils/src/lib/git.ts
|
|
609
|
-
import { simpleGit } from "simple-git";
|
|
610
|
-
|
|
611
622
|
// packages/utils/src/lib/logging.ts
|
|
612
623
|
import chalk2 from "chalk";
|
|
613
624
|
|
|
@@ -801,7 +812,7 @@ async function listAuditsAndGroups(eslint, patterns) {
|
|
|
801
812
|
}
|
|
802
813
|
|
|
803
814
|
// packages/plugin-eslint/src/lib/runner/index.ts
|
|
804
|
-
import {
|
|
815
|
+
import { writeFile } from "node:fs/promises";
|
|
805
816
|
import { dirname, join as join2 } from "node:path";
|
|
806
817
|
|
|
807
818
|
// packages/plugin-eslint/src/lib/setup.ts
|
|
@@ -818,18 +829,22 @@ function setupESLint(eslintrc) {
|
|
|
818
829
|
var WORKDIR = pluginWorkDir("eslint");
|
|
819
830
|
var RUNNER_OUTPUT_PATH = join2(WORKDIR, "runner-output.json");
|
|
820
831
|
var ESLINTRC_PATH = join2(process.cwd(), WORKDIR, ".eslintrc.json");
|
|
821
|
-
var
|
|
822
|
-
|
|
832
|
+
var PLUGIN_CONFIG_PATH = join2(
|
|
833
|
+
process.cwd(),
|
|
834
|
+
WORKDIR,
|
|
835
|
+
"plugin-config.json"
|
|
836
|
+
);
|
|
837
|
+
async function createRunnerConfig(scriptPath, audits, eslintrc, patterns) {
|
|
838
|
+
const config = {
|
|
839
|
+
eslintrc,
|
|
840
|
+
slugs: audits.map((audit) => audit.slug),
|
|
841
|
+
patterns: toArray(patterns)
|
|
842
|
+
};
|
|
843
|
+
await ensureDirectoryExists(dirname(PLUGIN_CONFIG_PATH));
|
|
844
|
+
await writeFile(PLUGIN_CONFIG_PATH, JSON.stringify(config));
|
|
823
845
|
return {
|
|
824
846
|
command: "node",
|
|
825
|
-
args: [
|
|
826
|
-
scriptPath,
|
|
827
|
-
audits.map((audit) => audit.slug).join(AUDIT_SLUGS_SEP),
|
|
828
|
-
eslintrc,
|
|
829
|
-
...toArray(patterns).map(
|
|
830
|
-
(pattern) => platform() === "win32" ? pattern : `'${pattern}'`
|
|
831
|
-
)
|
|
832
|
-
],
|
|
847
|
+
args: [scriptPath],
|
|
833
848
|
outputFile: RUNNER_OUTPUT_PATH
|
|
834
849
|
};
|
|
835
850
|
}
|
|
@@ -841,7 +856,7 @@ async function eslintPlugin(config) {
|
|
|
841
856
|
const { audits, groups } = await listAuditsAndGroups(eslint, patterns);
|
|
842
857
|
if (typeof eslintrc !== "string") {
|
|
843
858
|
await mkdir2(dirname2(ESLINTRC_PATH), { recursive: true });
|
|
844
|
-
await
|
|
859
|
+
await writeFile2(ESLINTRC_PATH, JSON.stringify(eslintrc));
|
|
845
860
|
}
|
|
846
861
|
const eslintrcPath = typeof eslintrc === "string" ? eslintrc : ESLINTRC_PATH;
|
|
847
862
|
const runnerScriptPath = join3(
|
|
@@ -858,7 +873,7 @@ async function eslintPlugin(config) {
|
|
|
858
873
|
version,
|
|
859
874
|
audits,
|
|
860
875
|
groups,
|
|
861
|
-
runner: createRunnerConfig(
|
|
876
|
+
runner: await createRunnerConfig(
|
|
862
877
|
runnerScriptPath,
|
|
863
878
|
audits,
|
|
864
879
|
eslintrcPath,
|
package/package.json
CHANGED
package/src/lib/config.d.ts
CHANGED
|
@@ -11,3 +11,8 @@ export declare const eslintPluginConfigSchema: z.ZodObject<{
|
|
|
11
11
|
patterns: (string | string[]) & (string | string[] | undefined);
|
|
12
12
|
}>;
|
|
13
13
|
export type ESLintPluginConfig = z.infer<typeof eslintPluginConfigSchema>;
|
|
14
|
+
export type ESLintPluginRunnerConfig = {
|
|
15
|
+
eslintrc: string;
|
|
16
|
+
slugs: string[];
|
|
17
|
+
patterns: string[];
|
|
18
|
+
};
|
|
@@ -2,5 +2,6 @@ import type { Audit, RunnerConfig } from '@code-pushup/models';
|
|
|
2
2
|
export declare const WORKDIR: string;
|
|
3
3
|
export declare const RUNNER_OUTPUT_PATH: string;
|
|
4
4
|
export declare const ESLINTRC_PATH: string;
|
|
5
|
-
export declare
|
|
6
|
-
export declare function
|
|
5
|
+
export declare const PLUGIN_CONFIG_PATH: string;
|
|
6
|
+
export declare function executeRunner(): Promise<void>;
|
|
7
|
+
export declare function createRunnerConfig(scriptPath: string, audits: Audit[], eslintrc: string, patterns: string | string[]): Promise<RunnerConfig>;
|