Files
react-native-devtools-frontend/scripts/test/run_lint_check_css.js
T
Jack Franklin d2a117c50f Remove lint-components-css script
Now we ban CSS in web components, this script is irrelevant as it'll
never find any issues - and we lint to ensure no style tags creep into
our Lit templates.

Bug: 1106746
Change-Id: I507193c63a1ab26901d9d3aaec2b01620717b477
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3075380
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2021-08-06 18:02:47 +00:00

57 lines
2.2 KiB
JavaScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const path = require('path');
const childProcess = require('child_process');
const {
devtoolsRootPath,
stylelintExecutablePath,
nodePath,
} = require('../devtools_paths.js');
const yargsObject = require('yargs')
.option('files', {type: 'array', desc: 'One or more files to lint.'})
.option('glob', {default: '**/*.css', desc: 'A glob to choose which files to lint.'})
.option('cwd', {default: devtoolsRootPath(), desc: 'Working directory to glob from'})
.parserConfiguration({
// So that if we pass --foo-bar, Yargs only populates
// argv with '--foo-bar', not '--foo-bar' and
// 'fooBar'. This is important because if we have both
// versions and pass them to stylelint, it errors
// saying that we've passed the same argument twice.
'camel-case-expansion': false
})
.argv;
// Note: stylelint requires POSIX-formatted paths/globs, even on Windows.
// The forward slash is not a bug.
const DEFAULT_GLOB = '**/*.css';
function getCSSFilesOrGlobList() {
const files = yargsObject.files || [];
if (files.length > 0) {
return files.map(file => {
// Enforce posix file paths even on Windows
return file.split(path.sep).join(path.posix.sep);
});
}
return [yargsObject.glob || DEFAULT_GLOB];
}
function run() {
// eslint-disable-next-line no-unused-vars
const {glob, files, cwd, _, $0, ...flagsForStylelint} = yargsObject;
const extraFlagsForStylelint = Object.keys(flagsForStylelint).flatMap(key => [`--${key}`, flagsForStylelint[key]]);
const args = [
stylelintExecutablePath(), ...getCSSFilesOrGlobList(), '--fix', '--allow-empty-input', ...extraFlagsForStylelint
];
const result = childProcess.spawnSync(nodePath(), args, {encoding: 'utf-8', cwd, stdio: 'inherit'});
process.exit(result.status);
}
run();