Skip to content

Commit 1592f62

Browse files
committed
refactor: full refactor + add tests
1 parent 7b090ca commit 1592f62

19 files changed

Lines changed: 343 additions & 98 deletions

nx.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"!{projectRoot}/**/?(*.)test.[jt]s?(x)?(.snap)",
1717
"!{projectRoot}/**/?(*.)mocks.[jt]s?(x)",
1818
"!{projectRoot}/**/?(*.)mock.[jt]s?(x)",
19+
"!{projectRoot}/vite.config.[jt]s",
1920
"!{projectRoot}/vitest.@(unit|int|e2e).config.[jt]s",
2021
"!{projectRoot}/dist/**/*",
2122
"!{projectRoot}/tsconfig.@(test|tools).json",
@@ -363,6 +364,12 @@
363364
}
364365
}
365366
},
367+
{
368+
"plugin": "@nx/eslint",
369+
"options": {
370+
"config": "{projectRoot}/eslint.config.js"
371+
}
372+
},
366373
{
367374
"plugin": "@nx/vite/plugin",
368375
"options": {

package-lock.json

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"commitizen": "^4.3.1",
8787
"commitlint-plugin-tense": "^1.0.3",
8888
"dotenv": "^16.4.5",
89+
"eslint-formatter-stylish": "^8.40.0",
8990
"eslint-import-resolver-typescript": "^3.6.1",
9091
"eslint-plugin-functional": "^7.1.0",
9192
"eslint-plugin-import": "2.31.0",

packages/plugin-eslint/src/lib/runner/lint.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function executeLint({
2525
patterns,
2626
}: ESLintTarget): Promise<ESLint.LintResult[]> {
2727
// running as CLI because ESLint#lintFiles() runs out of memory
28-
const { stdout } = await executeProcess({
28+
const { stdout, stderr, code } = await executeProcess({
2929
command: 'npx',
3030
args: [
3131
'eslint',
@@ -42,6 +42,12 @@ async function executeLint({
4242
cwd: process.cwd(),
4343
});
4444

45+
if (!stdout.trim()) {
46+
throw new Error(
47+
`ESLint produced empty output. Exit code: ${code}, STDERR: ${stderr}`,
48+
);
49+
}
50+
4551
return JSON.parse(stdout) as ESLint.LintResult[];
4652
}
4753

tools/eslint-multi-format/README.md renamed to tools/eslint-formatter-multiple-formats/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ESLint Multi-Format Formatter
1+
# ESLint Multiple-Formats Formatter
22

33
The ESLint plugin uses a custom formatter that supports multiple output formats and destinations simultaneously.
44

@@ -14,7 +14,7 @@ Use the `ESLINT_FORMATTER_CONFIG` environment variable to configure the formatte
1414
"filename": "eslint-report", // Optional: Base filename without extension (default: 'eslint-report')
1515
"formats": ["json"], // Optional: Array of format names for file output (default: ['json'])
1616
"terminal": "stylish", // Optional: Format for terminal output (default: 'stylish')
17-
"verbose": true // Optional: Enable verbose logging (default: false)
17+
"verbose": true, // Optional: Enable verbose logging (default: false)
1818
}
1919
```
2020

File renamed without changes.

tools/eslint-multi-format/package.json renamed to tools/eslint-formatter-multiple-formats/package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
{
2-
"name": "eslint-formatter-multi-format",
2+
"name": "eslint-formatter-multiple-formats",
33
"version": "0.0.1",
44
"private": false,
55
"type": "module",
6-
"main": "./index.js",
7-
"types": "./index.d.ts",
6+
"main": "./src/index.js",
7+
"types": "./src/index.d.ts",
8+
"engines": {
9+
"node": ">=17.0.0"
10+
},
811
"description": "ESLint formatter that supports multiple output formats and destinations simultaneously",
912
"author": "Michael Hladky",
1013
"license": "MIT",
1114
"repository": {
1215
"type": "git",
1316
"url": "https://github.com/code-pushup/cli.git",
14-
"directory": "tools/eslint-multi-format"
17+
"directory": "tools/eslint-formatter-multiple-formats"
1518
},
1619
"keywords": [
1720
"eslint",
@@ -22,14 +25,14 @@
2225
"linting"
2326
],
2427
"files": [
25-
"index.js",
26-
"index.d.ts",
27-
"lib/",
28-
"README.md",
29-
"package.json"
28+
"src/*",
29+
"README.md"
3030
],
31-
"engines": {
32-
"node": ">=18.0.0"
31+
"publishConfig": {
32+
"access": "public"
33+
},
34+
"dependencies": {
35+
"eslint-formatter-stylish": "^8.40.0"
3336
},
3437
"peerDependencies": {
3538
"eslint": "^8.0.0 || ^9.0.0"

tools/eslint-multi-format/project.json renamed to tools/eslint-formatter-multiple-formats/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
"name": "eslint-multi-formatter",
2+
"name": "eslint-formatter-multiple-formats",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"sourceRoot": "tools/eslint-multi-format/src",
55
"projectType": "library",
66
"tags": [],
77
"// targets": "to see all targets run: nx show project eslint-multi-format with option --web for humans and --json for AI",
88
"targets": {
99
"lint": {},
10+
"unit-test": {},
1011
"build": {
1112
"executor": "@nx/vite:build",
1213
"outputs": ["{options.outputPath}"],
File renamed without changes.

tools/eslint-multi-format/src/lib/multiple-formats.ts renamed to tools/eslint-formatter-multiple-formats/src/lib/multiple-formats.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { ESLint } from 'eslint';
22
import path from 'node:path';
33
import type { EslintFormat, FormatterConfig } from './types.js';
44
import {
5+
formatTerminalOutput,
56
findConfigFromEnv as getConfigFromEnv,
6-
getTerminalOutput,
77
persistEslintReports,
88
} from './utils.js';
99

@@ -58,8 +58,6 @@ export default function multipleFormats(
5858
verbose = false,
5959
} = config;
6060

61-
const terminalOutput = getTerminalOutput(terminal, results);
62-
6361
try {
6462
persistEslintReports(formats, results, {
6563
outputDir,
@@ -72,5 +70,5 @@ export default function multipleFormats(
7270
}
7371
}
7472

75-
return terminalOutput;
73+
return formatTerminalOutput(terminal, results);
7674
}

0 commit comments

Comments
 (0)