Skip to content

Commit 77ba8df

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[stylelint] Run test on Presubmit
We missed running this test and thus didn't catch some changes. Bug: none Change-Id: I4781780c6df539671bf3191b888fb8ca8ae436b2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6401394 Reviewed-by: Benedikt Meurer <[email protected]> Reviewed-by: Liviu Rau <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent eb541d6 commit 77ba8df

File tree

4 files changed

+159
-55
lines changed

4 files changed

+159
-55
lines changed

PRESUBMIT.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,15 @@ def _CheckDevToolsRunESLintTests(input_api, output_api):
173173
sys.path = original_sys_path
174174
eslint_rules_dir_path = input_api.os_path.join(
175175
input_api.PresubmitLocalPath(), 'scripts', 'eslint_rules')
176-
eslint_rules_affected_files = _getAffectedFiles(input_api,
177-
[eslint_rules_dir_path],
178-
[], [])
176+
eslint_rules_checked_paths = [
177+
# Check if EsLint is updated
178+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
179+
'eslint'),
180+
# Check for rules changes
181+
eslint_rules_dir_path,
182+
]
183+
eslint_rules_affected_files = _getAffectedFiles(
184+
input_api, eslint_rules_checked_paths, [], [])
179185

180186
if (len(eslint_rules_affected_files) == 0):
181187
return []
@@ -193,6 +199,54 @@ def _CheckDevToolsRunESLintTests(input_api, output_api):
193199
return results
194200

195201

202+
def _CheckDevToolsRunStylelintTests(input_api, output_api):
203+
# Check for changes in the stylelint_rules directory, and run the stylelint rules
204+
# tests if so.
205+
# We don't do this on every CL as most do not touch the rules, but if we do
206+
# change them we need to make sure all the tests are passing.
207+
original_sys_path = sys.path
208+
try:
209+
sys.path = sys.path + [
210+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts')
211+
]
212+
import devtools_paths
213+
finally:
214+
sys.path = original_sys_path
215+
216+
stylelint_tests_path = input_api.os_path.join(
217+
input_api.PresubmitLocalPath(), 'scripts', 'stylelint_rules')
218+
stylelint_rules_check_paths = [
219+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
220+
'stylelint'),
221+
# Rule is added/updated
222+
stylelint_tests_path,
223+
# Variable declaration used in test are changed
224+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end',
225+
'application_tokens.css'),
226+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end',
227+
'design_system_tokens.css'),
228+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end',
229+
'inspectorCommon.css'),
230+
]
231+
stylelint_rules_affected_files = _getAffectedFiles(
232+
input_api, stylelint_rules_check_paths, [], [])
233+
234+
if (len(stylelint_rules_affected_files) == 0):
235+
return []
236+
237+
mocha_path = devtools_paths.mocha_path()
238+
stylelint_tests_path = input_api.os_path.join(stylelint_tests_path,
239+
'tests', '*.test.js')
240+
241+
results = [output_api.PresubmitNotifyResult('Stylelint rules unit tests')]
242+
results.extend(
243+
# The dot reporter is more concise which is useful to not get LOADS of
244+
# output when just one test fails.
245+
_checkWithNodeScript(input_api, output_api, mocha_path,
246+
['--reporter', 'dot', stylelint_tests_path]))
247+
return results
248+
249+
196250
def _CheckDevToolsRunBuildTests(input_api, output_api):
197251
# Check for changes in the build/tests directory, and run the tests if so.
198252
# We don't do this on every CL as most do not touch the rules, but if we do
@@ -234,9 +288,7 @@ def _CheckDevToolsLint(input_api, output_api):
234288

235289
front_end_directory = input_api.os_path.join(
236290
input_api.PresubmitLocalPath(), 'front_end')
237-
component_docs_directory = input_api.os_path.join(front_end_directory,
238-
'ui', 'components',
239-
'docs')
291+
240292
inspector_overlay_directory = input_api.os_path.join(
241293
input_api.PresubmitLocalPath(), 'inspector_overlay')
242294
test_directory = input_api.os_path.join(input_api.PresubmitLocalPath(),
@@ -530,6 +582,7 @@ def _CommonChecks(canned_checks):
530582
_CheckGeneratedFiles,
531583
_CheckDevToolsLint,
532584
_CheckDevToolsRunESLintTests,
585+
_CheckDevToolsRunStylelintTests,
533586
_CheckDevToolsRunBuildTests,
534587
_CheckDevToolsNonJSFileLicenseHeaders,
535588
_CheckFormat,

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ export default [
577577
rules: {
578578
'no-console': 'off',
579579
'rulesdir/es-modules-import': 'off',
580+
'import/no-default-export': 'off',
580581
},
581582
},
582583
{

scripts/stylelint_rules/lib/use_theme_colors.mjs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ const {
1515
const RULE_NAME = 'plugin/use_theme_colors';
1616

1717
const CSS_PROPS_TO_CHECK_FOR_COLOR_USAGE = new Set([
18-
'color',
19-
'box-shadow',
20-
'text-shadow',
21-
'outline-color',
22-
'background-image',
18+
'-webkit-border-image',
2319
'background-color',
24-
'border-left-color',
25-
'border-right-color',
26-
'border-top-color',
20+
'background-image',
21+
'background',
2722
'border-bottom-color',
28-
'-webkit-border-image',
29-
'fill',
30-
'stroke',
23+
'border-bottom',
24+
'border-color',
25+
'border-left-color',
3126
'border-left',
27+
'border-right-color',
3228
'border-right',
29+
'border-top-color',
3330
'border-top',
34-
'border-bottom',
35-
'background',
3631
'border',
37-
'border-color',
32+
'box-shadow',
33+
'color',
34+
'fill',
35+
'outline-color',
3836
'outline',
37+
'stroke',
38+
'text-shadow',
3939
]);
4040

4141
const borderCombinedDeclarations = new Set([
@@ -56,20 +56,20 @@ const COLOR_INDICATOR_REGEXES = new Set([
5656
const CUSTOM_VARIABLE_OVERRIDE_PREFIX = '--override-';
5757

5858
const applicationTokensPath = join(
59-
import.meta.dirname,
60-
'..',
61-
'..',
62-
'..',
63-
'front_end',
64-
'application_tokens.css',
59+
import.meta.dirname,
60+
'..',
61+
'..',
62+
'..',
63+
'front_end',
64+
'application_tokens.css',
6565
);
6666
const designSystemTokensPath = join(
67-
import.meta.dirname,
68-
'..',
69-
'..',
70-
'..',
71-
'front_end',
72-
'design_system_tokens.css',
67+
import.meta.dirname,
68+
'..',
69+
'..',
70+
'..',
71+
'front_end',
72+
'design_system_tokens.css',
7373
);
7474
const inspectorCommonPath = join(
7575
import.meta.dirname,
@@ -99,14 +99,15 @@ function getRootVariableDeclarationsFromCSSFile(filePath) {
9999

100100
const DEFINED_APPLICATION_COLOR_VARIABLES =
101101
getRootVariableDeclarationsFromCSSFile(applicationTokensPath);
102-
const DEFINED_THEME_COLOR_VARIABLES =
103-
getRootVariableDeclarationsFromCSSFile(designSystemTokensPath);
102+
const DEFINED_THEME_COLOR_VARIABLES = getRootVariableDeclarationsFromCSSFile(
103+
designSystemTokensPath,
104+
);
104105
const DEFINED_INSPECTOR_STYLE_VARIABLES =
105106
getRootVariableDeclarationsFromCSSFile(inspectorCommonPath);
106107
const ALL_DEFINED_VARIABLES = new Set([
107108
...DEFINED_APPLICATION_COLOR_VARIABLES,
108109
...DEFINED_THEME_COLOR_VARIABLES,
109-
...DEFINED_INSPECTOR_STYLE_VARIABLES,
110+
...DEFINED_INSPECTOR_STYLE_VARIABLES,
110111
]);
111112

112113
const BOX_SHADOW_VARIABLES = new Set(
@@ -302,8 +303,7 @@ const ruleFunction = (primary, secondary, context) => {
302303
const partsOfValue = /(.+)\s(\w+)\s(.+)/.exec(declaration.value);
303304

304305
if (partsOfValue) {
305-
// eslint-disable-next-line no-unused-vars
306-
const [, lineSize, lineStyle, lineColor] = partsOfValue;
306+
const [, , , lineColor] = partsOfValue;
307307
// Line color is the only part we want to check as it's the only bit
308308
// that could contain color.
309309
checkColorValueIsValidOrError({
@@ -331,5 +331,4 @@ const ruleFunction = (primary, secondary, context) => {
331331
ruleFunction.ruleName = RULE_NAME;
332332
ruleFunction.messages = ruleMessages(RULE_NAME, {});
333333

334-
// eslint-disable-next-line import/no-default-export
335334
export default createPlugin(RULE_NAME, ruleFunction);

0 commit comments

Comments
 (0)