|
|
|
@ -1,4 +1,3 @@ |
|
|
|
|
// @ts-check |
|
|
|
|
const { ESLintUtils, AST_NODE_TYPES } = require('@typescript-eslint/utils'); |
|
|
|
|
|
|
|
|
|
const createRule = ESLintUtils.RuleCreator( |
|
|
|
@ -8,36 +7,17 @@ const createRule = ESLintUtils.RuleCreator( |
|
|
|
|
const borderRadiusRule = createRule({ |
|
|
|
|
create(context) { |
|
|
|
|
return { |
|
|
|
|
CallExpression(node) { |
|
|
|
|
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'css') { |
|
|
|
|
const cssObjects = node.arguments.flatMap((node) => { |
|
|
|
|
switch (node.type) { |
|
|
|
|
case AST_NODE_TYPES.ObjectExpression: |
|
|
|
|
return [node]; |
|
|
|
|
case AST_NODE_TYPES.ArrayExpression: |
|
|
|
|
return node.elements.filter((v) => v?.type === AST_NODE_TYPES.ObjectExpression); |
|
|
|
|
default: |
|
|
|
|
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', |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
for (const cssObject of cssObjects) { |
|
|
|
|
if (cssObject?.type === AST_NODE_TYPES.ObjectExpression) { |
|
|
|
|
for (const property of cssObject.properties) { |
|
|
|
|
if ( |
|
|
|
|
property.type === AST_NODE_TYPES.Property && |
|
|
|
|
property.key.type === AST_NODE_TYPES.Identifier && |
|
|
|
|
property.key.name === 'borderRadius' && |
|
|
|
|
property.value.type === AST_NODE_TYPES.Literal |
|
|
|
|
) { |
|
|
|
|
context.report({ |
|
|
|
|
node: property, |
|
|
|
|
messageId: 'borderRadiusId', |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|