Skip to content

Commit 4dc470b

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Fix when running with .
Fixes some issue around what gets ignored when linting. Found while running `npm run lint -- .` Bug: 397260638 Change-Id: I858b9078611a3cb9f31c60ff3e18d99b56563d73 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6280813 Reviewed-by: Philip Pfaffe <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Mathias Bynens <[email protected]>
1 parent d593a7b commit 4dc470b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

eslint.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export default [
3333
'build/',
3434
'buildtools/',
3535

36+
// Don't include the common build directory
37+
'out/',
38+
// Don't include third party code
39+
'third_party/',
40+
3641
'front_end/diff/diff_match_patch.jD',
3742
'front_end/models/javascript_metadata/NativeFunctions.js',
3843
// All of these scripts are auto-generated so don't lint them.

scripts/test/run_lint_check.mjs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { spawn } from 'child_process';
66
import { ESLint } from 'eslint';
77
import { readFileSync } from 'fs';
88
import { sync } from 'globby';
9-
import { extname, join } from 'path';
9+
import { extname, join, resolve, relative } from 'path';
1010
import stylelint from 'stylelint';
1111
import yargs from 'yargs';
1212
import { hideBin } from 'yargs/helpers';
@@ -247,12 +247,37 @@ async function runLitAnalyzer(files) {
247247
return results.every(r => r.status);
248248
}
249249

250+
const DEVTOOLS_ROOT_DIR = resolve(import.meta.dirname, '..', '..');
251+
/**
252+
*
253+
* @param {string} path
254+
* @returns {boolean}
255+
*/
256+
function shouldIgnoreFile(path) {
257+
const resolvedPath = resolve(path);
258+
const relativePath = relative(DEVTOOLS_ROOT_DIR, resolvedPath);
259+
260+
if (
261+
relativePath.includes('third_party') ||
262+
relativePath.includes('node_modules')
263+
) {
264+
return true;
265+
}
266+
267+
return false;
268+
}
269+
250270
async function run() {
251271
const scripts = [];
252272
const styles = [];
253273
for (const path of sync(flags.files, {
254274
expandDirectories: { extensions: ['css', 'mjs', 'js', 'ts'] },
275+
gitignore: true,
255276
})) {
277+
if (shouldIgnoreFile(path)) {
278+
continue;
279+
}
280+
256281
if (extname(path) === '.css') {
257282
styles.push(path);
258283
} else {

0 commit comments

Comments
 (0)