Skip to content

Commit 0d4dbae

Browse files
committed
[lint] Read lit-analyzer options from toplevel tsconfig.json.
This way the config is in a central place and can be reused for ts-lit-plugin. Bug: 375149136 Change-Id: Ic3805b059b5c9b0d103a152e1ff36b3c9c5245b6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5953717 Auto-Submit: Benedikt Meurer <[email protected]> Reviewed-by: Danil Somsikov <[email protected]>
1 parent 9b1acc7 commit 0d4dbae

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

scripts/devtools_paths.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ function litAnalyzerExecutablePath() {
129129
return path.join(nodeModulesPath(), 'lit-analyzer', 'cli.js');
130130
}
131131

132+
/**
133+
* Computes the path to the toplevel `tsconfig.json`.
134+
*
135+
* @returns the path to the toplevel `tsconfig.json`.
136+
*/
137+
function tsconfigJsonPath() {
138+
return path.join(devtoolsRootPath(), 'tsconfig.json');
139+
}
140+
132141
function downloadedChromeBinaryPath() {
133142
const paths = {
134143
linux: path.join('chrome-linux', 'chrome'),
@@ -146,5 +155,6 @@ module.exports = {
146155
mochaExecutablePath,
147156
stylelintExecutablePath,
148157
downloadedChromeBinaryPath,
149-
litAnalyzerExecutablePath
158+
litAnalyzerExecutablePath,
159+
tsconfigJsonPath,
150160
};

scripts/test/run_lint_check.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ const yargs = require('yargs/yargs');
1313
const {hideBin} = require('yargs/helpers');
1414
const childProcess = require('child_process');
1515
const {promisify} = require('util');
16+
const {readFileSync} = require('fs');
1617
const spawnAsync = promisify(childProcess.spawnSync);
1718

1819
const {
1920
devtoolsRootPath,
2021
litAnalyzerExecutablePath,
2122
nodePath,
23+
tsconfigJsonPath,
2224
} = require('../devtools_paths.js');
2325

2426
const flags = yargs(hideBin(process.argv))
@@ -91,14 +93,25 @@ async function runStylelint(files) {
9193
}
9294

9395
/**
94-
* @param {string[]} files
96+
* Runs the `lit-analyzer` on the `files`.
97+
*
98+
* The configuration for the `lit-analyzer` is parsed from the options for
99+
* the "ts-lit-plugin" from the toplevel `tsconfig.json` file.
100+
*
101+
* @param {string[]} files the input files to analyze.
95102
*/
96103
async function runLitAnalyzer(files) {
97-
const rules = {
98-
'no-missing-import': 'error',
99-
'no-unknown-tag-name': 'error',
100-
'no-complex-attribute-binding': 'off',
104+
const readLitAnalyzerConfigFromCompilerOptions = () => {
105+
const {compilerOptions} = JSON.parse(readFileSync(tsconfigJsonPath(), 'utf-8'));
106+
const {plugins} = compilerOptions;
107+
const tsLitPluginOptions = plugins.find(plugin => plugin.name === 'ts-lit-plugin');
108+
if (tsLitPluginOptions === null) {
109+
throw new Error(`Failed to find ts-lit-plugin options in ${tsconfigJsonPath()}`);
110+
}
111+
return tsLitPluginOptions;
101112
};
113+
114+
const {rules} = readLitAnalyzerConfigFromCompilerOptions();
102115
const getLitAnalyzerResult = async subsetFiles => {
103116
const args = [
104117
litAnalyzerExecutablePath(),

tsconfig.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./config/typescript/tsconfig.base.json",
33
"compilerOptions": {
4+
"allowUmdGlobalAccess": true,
45
"lib": [
56
"esnext",
67
"dom",
@@ -9,7 +10,16 @@
910
"webworker.iterable"
1011
],
1112
"outDir": "ignored-for-vscode",
12-
"allowUmdGlobalAccess": true
13+
"plugins": [
14+
{
15+
"name": "ts-lit-plugin",
16+
"rules": {
17+
"no-complex-attribute-binding": "off",
18+
"no-missing-import": "error",
19+
"no-unknown-tag-name": "error"
20+
}
21+
}
22+
]
1323
},
1424
"include": [
1525
"front_end/",

0 commit comments

Comments
 (0)