Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripts): make lint errors reporting propagate to STDOUT during pre-commit (lint-staged exec) #26212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: add cypress.config to config files glob to fix linting",
"packageName": "@fluentui/eslint-plugin",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/utils/configHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const docsFiles = ['**/*Page.tsx', '**/{docs,demo}/**', '**/*.doc.{ts,tsx}'];

const configFiles = [
'./just.config.ts',
'./cypress.config.ts',
'./gulpfile.ts',
'./*.js',
'./.*.js',
Expand Down
14 changes: 8 additions & 6 deletions scripts/lint-staged/eslint-for-package.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @ts-check

const micromatch = require('micromatch');
const fs = require('fs-extra');
const path = require('path');
const { ESLint } = require('eslint');
const fs = require('fs-extra');
const micromatch = require('micromatch');

const { eslintConstants } = require('../monorepo');

/**
Expand Down Expand Up @@ -57,18 +58,19 @@ async function run() {

// Lint files then fix all auto-fixable issues
const results = await eslint.lintFiles(filteredFiles);

await ESLint.outputFixes(results);

// Format results
const formatter = await eslint.loadFormatter();
const resultText = formatter.format(results);
if (resultText) {
console.error(resultText);
process.exit(1);
throw new Error(resultText);
}
}

run().catch(err => {
console.log(err);
process.exit(1);
// logging is handled by ./eslint.js. If you wanna directly call this script and see errors uncomment following line ↓
// console.error(err);
throw new Error(err);
});
8 changes: 6 additions & 2 deletions scripts/lint-staged/eslint.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check

// eslint-disable-next-line @typescript-eslint/naming-convention, camelcase
const child_process = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { promisify } = require('util');
const child_process = require('child_process');
const { rollup: lernaAliases } = require('lerna-alias');
const { default: PQueue } = require('p-queue');
const exec = promisify(child_process.exec);
Expand Down Expand Up @@ -66,11 +67,14 @@ async function runEslintOnFilesGroupedPerPackage() {

await queue.addAll(
Object.entries(filesGroupedByPackage).map(([packagePath, files]) => async () => {
const cmd = `node ${eslintForPackageScript} ${files.join(' ')}`;

// This script handles running eslint on ONLY the appropriate files for each package.
// See its comments for more details.
return exec(`node ${eslintForPackageScript} ${files.join(' ')}`, { cwd: packagePath }).catch(() => {
return exec(cmd, { cwd: packagePath }).catch((/** @type {{ stdout: string, stderr: string }} */ err) => {
// The subprocess should already have handled logging. Just mark that there was an error.
hasError = true;
throw new Error(err.stderr);
});
}),
);
Expand Down