mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 19:52:35 +08:00

* 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>
40 lines
1.1 KiB
JavaScript
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;
|