Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
plugins: [
await eslintPlugin(
{ patterns: ['src/*.js'] },
{
artifacts: {
generateArtifactsCommand:
'npx eslint src/*.js --format json --output-file ./.code-pushup/eslint-report.json',
artifactsPaths: ['./.code-pushup/eslint-report.json'],
},
},
),
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import('eslint').Linter.Config[]} */
module.exports = [
{
ignores: ['code-pushup.config.ts'],
},
{
rules: {
eqeqeq: 'error',
'max-lines': ['warn', 100],
'no-unused-vars': 'warn',
},
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function unusedFn() {
return '42';
}

module.exports = function orwell() {
if (2 + 2 == 5) {
console.log(1984);
}
};
232 changes: 232 additions & 0 deletions e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,235 @@ exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLin
],
}
`;

exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLint plugin with artifacts options 1`] = `
{
"packageName": "@code-pushup/core",
"plugins": [
{
"audits": [
{
"description": "ESLint rule **eqeqeq**.",
"details": {
"issues": [
{
"message": "Expected '===' and instead saw '=='.",
"severity": "error",
"source": {
"file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js",
"position": {
"endColumn": 15,
"endLine": 6,
"startColumn": 13,
"startLine": 6,
},
},
},
],
},
"displayValue": "1 error",
"docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq",
"score": 0,
"slug": "eqeqeq",
"title": "Require the use of \`===\` and \`!==\`",
"value": 1,
},
{
"description": "ESLint rule **max-lines**.

Custom options:

\`\`\`json
100
\`\`\`",
"details": {
"issues": [],
},
"displayValue": "passed",
"docsUrl": "https://eslint.org/docs/latest/rules/max-lines",
"score": 1,
"slug": "max-lines-71b54366cb01f77b",
"title": "Enforce a maximum number of lines per file",
"value": 0,
},
{
"description": "ESLint rule **no-unused-vars**.",
"details": {
"issues": [
{
"message": "'unusedFn' is defined but never used.",
"severity": "warning",
"source": {
"file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js",
"position": {
"endColumn": 18,
"endLine": 1,
"startColumn": 10,
"startLine": 1,
},
},
},
],
},
"displayValue": "1 warning",
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
"score": 0,
"slug": "no-unused-vars",
"title": "Disallow unused variables",
"value": 1,
},
],
"description": "Official Code PushUp ESLint plugin",
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
"groups": [
{
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
"refs": [
{
"slug": "no-unused-vars",
"weight": 1,
},
],
"slug": "problems",
"title": "Problems",
},
{
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
"refs": [
{
"slug": "eqeqeq",
"weight": 1,
},
{
"slug": "max-lines-71b54366cb01f77b",
"weight": 1,
},
],
"slug": "suggestions",
"title": "Suggestions",
},
],
"icon": "eslint",
"packageName": "@code-pushup/eslint-plugin",
"slug": "eslint",
"title": "ESLint",
},
],
}
`;

exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLint plugin with artifacts options and create eslint-report.json and report.json 1`] = `
{
"packageName": "@code-pushup/core",
"plugins": [
{
"audits": [
{
"description": "ESLint rule **eqeqeq**.",
"details": {
"issues": [
{
"message": "Expected '===' and instead saw '=='.",
"severity": "error",
"source": {
"file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js",
"position": {
"endColumn": 15,
"endLine": 6,
"startColumn": 13,
"startLine": 6,
},
},
},
],
},
"displayValue": "1 error",
"docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq",
"score": 0,
"slug": "eqeqeq",
"title": "Require the use of \`===\` and \`!==\`",
"value": 1,
},
{
"description": "ESLint rule **max-lines**.

Custom options:

\`\`\`json
100
\`\`\`",
"details": {
"issues": [],
},
"displayValue": "passed",
"docsUrl": "https://eslint.org/docs/latest/rules/max-lines",
"score": 1,
"slug": "max-lines-71b54366cb01f77b",
"title": "Enforce a maximum number of lines per file",
"value": 0,
},
{
"description": "ESLint rule **no-unused-vars**.",
"details": {
"issues": [
{
"message": "'unusedFn' is defined but never used.",
"severity": "warning",
"source": {
"file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js",
"position": {
"endColumn": 18,
"endLine": 1,
"startColumn": 10,
"startLine": 1,
},
},
},
],
},
"displayValue": "1 warning",
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
"score": 0,
"slug": "no-unused-vars",
"title": "Disallow unused variables",
"value": 1,
},
],
"description": "Official Code PushUp ESLint plugin",
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
"groups": [
{
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
"refs": [
{
"slug": "no-unused-vars",
"weight": 1,
},
],
"slug": "problems",
"title": "Problems",
},
{
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
"refs": [
{
"slug": "eqeqeq",
"weight": 1,
},
{
"slug": "max-lines-71b54366cb01f77b",
"weight": 1,
},
],
"slug": "suggestions",
"title": "Suggestions",
},
],
"icon": "eslint",
"packageName": "@code-pushup/eslint-plugin",
"slug": "eslint",
"title": "ESLint",
},
],
}
`;
28 changes: 28 additions & 0 deletions e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => {
);
const fixturesFlatConfigDir = path.join(fixturesDir, 'flat-config');
const fixturesLegacyConfigDir = path.join(fixturesDir, 'legacy-config');
const fixturesArtifactsConfigDir = path.join(fixturesDir, 'artifacts-config');

const envRoot = path.join(
E2E_ENVIRONMENTS_DIR,
Expand All @@ -28,22 +29,32 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => {
);
const flatConfigDir = path.join(envRoot, 'flat-config');
const legacyConfigDir = path.join(envRoot, 'legacy-config');
const artifactsConfigDir = path.join(envRoot, 'artifacts-config');
const flatConfigOutputDir = path.join(flatConfigDir, '.code-pushup');
const legacyConfigOutputDir = path.join(legacyConfigDir, '.code-pushup');
const artifactsConfigOutputDir = path.join(
artifactsConfigDir,
'.code-pushup',
);

beforeAll(async () => {
await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true });
await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true });
await cp(fixturesArtifactsConfigDir, artifactsConfigDir, {
recursive: true,
});
});

afterAll(async () => {
await teardownTestFolder(flatConfigDir);
await teardownTestFolder(legacyConfigDir);
await teardownTestFolder(artifactsConfigDir);
});

afterEach(async () => {
await teardownTestFolder(flatConfigOutputDir);
await teardownTestFolder(legacyConfigOutputDir);
await teardownTestFolder(artifactsConfigOutputDir);
});

it('should run ESLint plugin for flat config and create report.json', async () => {
Expand Down Expand Up @@ -80,4 +91,21 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => {
expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});

it('should run ESLint plugin with artifacts options and create eslint-report.json and report.json', async () => {
const { code } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', 'collect', '--no-progress'],
cwd: artifactsConfigDir,
});

expect(code).toBe(0);

const report = await readJsonFile(
path.join(artifactsConfigOutputDir, 'report.json'),
);

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
},
"code-pushup-eslint": {
"cache": true,
"inputs": ["default", "code-pushup-inputs", "lint-eslint-inputs"],
"inputs": ["default", "code-pushup-inputs"],
"outputs": ["{projectRoot}/.code-pushup/eslint/runner-output.json"],
"executor": "nx:run-commands",
"options": {
Expand Down
Loading
Loading