Skip to content

Commit

Permalink
fix(scripts): make lint errors reporting propagate to STDOUT during p…
Browse files Browse the repository at this point in the history
…re-commit (lint-staged exec) (microsoft#26212)

* fix(eslint-plugin): add cypress.config to config files glob to fix linting

* fix(scripts): make lint errors reporting propagate to STDOUT

* generate change-file
  • Loading branch information
Hotell committed Feb 9, 2023
1 parent d5766be commit d7f05b3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
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

0 comments on commit d7f05b3

Please sign in to comment.