From 4b1e551057eedd5a572f5491e7004be7c9b42246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20Jos=C3=A9povic?= Date: Fri, 29 Dec 2023 21:49:06 -0500 Subject: [PATCH] @stylex/eslint-plugin: Change message when limit set to null --- .../eslint-plugin/__tests__/stylex-valid-styles-test.js | 9 +++------ packages/eslint-plugin/src/rules/makeUnionRule.js | 5 ++++- packages/eslint-plugin/src/stylex-valid-styles.js | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin/__tests__/stylex-valid-styles-test.js b/packages/eslint-plugin/__tests__/stylex-valid-styles-test.js index 07d5b54a..352cb342 100644 --- a/packages/eslint-plugin/__tests__/stylex-valid-styles-test.js +++ b/packages/eslint-plugin/__tests__/stylex-valid-styles-test.js @@ -1238,8 +1238,7 @@ revert`, ], errors: [ { - message: `grid value must be one of: -grid properties disallowed for testing`, + message: 'Property grid is not allowed. grid properties disallowed for testing', }, ], }, @@ -1265,8 +1264,7 @@ grid properties disallowed for testing`, ], errors: [ { - message: `gridTemplateColumns value must be one of: -grid properties disallowed for testing`, + message: 'Property gridTemplateColumns is not allowed. grid properties disallowed for testing', }, ], }, @@ -1287,8 +1285,7 @@ grid properties disallowed for testing`, ], errors: [ { - message: `grid value must be one of: -This property is not supported in legacy StyleX resolution.`, + message: 'Property grid is not allowed. This property is not supported in legacy StyleX resolution.', }, ], }, diff --git a/packages/eslint-plugin/src/rules/makeUnionRule.js b/packages/eslint-plugin/src/rules/makeUnionRule.js index 198ff38b..99c9148a 100644 --- a/packages/eslint-plugin/src/rules/makeUnionRule.js +++ b/packages/eslint-plugin/src/rules/makeUnionRule.js @@ -23,6 +23,7 @@ export default function makeUnionRule( node: Expression | Pattern, variables?: Variables, prop?: Property, + key?: string, ): RuleResponse => { const failedRules = []; for (const _rule of rules) { @@ -43,8 +44,10 @@ export default function makeUnionRule( const fixable = failedRules.filter((a) => a.suggest != null); fixable.sort((a, b) => (a.distance || Infinity) - (b.distance || Infinity)); + const enumValues = failedRules.map((a) => a.message).join('\n') + return { - message: failedRules.map((a) => a.message).join('\n'), + message: key ? `${key} value must be one of:\n${enumValues}` : enumValues, suggest: fixable[0] != null ? fixable[0].suggest : undefined, }; }; diff --git a/packages/eslint-plugin/src/stylex-valid-styles.js b/packages/eslint-plugin/src/stylex-valid-styles.js index b6c6d685..28349fb0 100644 --- a/packages/eslint-plugin/src/stylex-valid-styles.js +++ b/packages/eslint-plugin/src/stylex-valid-styles.js @@ -50,6 +50,7 @@ export type RuleCheck = ( node: $ReadOnly, variables?: Variables, prop?: $ReadOnly, + key?: string, ) => RuleResponse; export type RuleResponse = void | { message: string, @@ -62,7 +63,7 @@ export type RuleResponse = void | { const showError = (message: string): RuleCheck => - () => ({ message }); + (_node, _variables, _props, key) => ({ message: key ? `Property ${key} is not allowed. ${message}` : message }); const isStringOrNumber = makeUnionRule(isString, isNumber); @@ -2624,14 +2625,14 @@ const stylexValidStyles = { } } - const check = ruleChecker(style.value, varsWithFnArgs, style); + const check = ruleChecker(style.value, varsWithFnArgs, style, key); if (check != null) { const { message, suggest } = check; return context.report( ({ node: style.value, loc: style.value.loc, - message: `${key} value must be one of:\n${message}${ + message: `${message}${ key === 'lineHeight' ? '\nBe careful when fixing: lineHeight: 10px is not the same as lineHeight: 10' : ''