Files
grafana/packages/grafana-eslint-rules/rules/no-border-radius-literal.cjs
Ashley Harrison b56a4a5295 Border radius: Improve rule and fix remaining violations (#104569)
* improve rule and fix remaining borderRadius violations

* prettier

* Add test case for nested classes

* Fix unnecessary string wrapping

---------

Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
2025-04-30 14:03:54 +01:00

40 lines
1.1 KiB
JavaScript

const { ESLintUtils, AST_NODE_TYPES } = require('@typescript-eslint/utils');
const createRule = ESLintUtils.RuleCreator(
(name) => `https://github.com/grafana/grafana/blob/main/packages/grafana-eslint-rules/README.md#${name}`
);
const borderRadiusRule = createRule({
create(context) {
return {
[`${AST_NODE_TYPES.CallExpression}[callee.name="css"] ${AST_NODE_TYPES.Property}`]: function (node) {
if (
node.type === AST_NODE_TYPES.Property &&
node.key.type === AST_NODE_TYPES.Identifier &&
node.key.name === 'borderRadius' &&
node.value.type === AST_NODE_TYPES.Literal
) {
context.report({
node,
messageId: 'borderRadiusId',
});
}
},
};
},
name: 'no-border-radius-literal',
meta: {
type: 'problem',
docs: {
description: 'Check if border-radius theme tokens are used',
},
messages: {
borderRadiusId: 'Prefer using theme.shape.radius tokens instead of literal values.',
},
schema: [],
},
defaultOptions: [],
});
module.exports = borderRadiusRule;