mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Fix custom eslint rule typechecking (#85886)
This commit is contained in:
parent
85e66d8edb
commit
7aac5f6b3e
@ -5,6 +5,9 @@
|
|||||||
"main": "./index.cjs",
|
"main": "./index.cjs",
|
||||||
"author": "Grafana Labs",
|
"author": "Grafana Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --emitDeclarationOnly false --noEmit"
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/grafana/grafana.git",
|
"url": "http://github.com/grafana/grafana.git",
|
||||||
|
@ -2,15 +2,15 @@
|
|||||||
const { ESLintUtils } = require('@typescript-eslint/utils');
|
const { ESLintUtils } = require('@typescript-eslint/utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import("@typescript-eslint/types/dist/generated/ast-spec").Expression} Expression
|
* @typedef {import("@typescript-eslint/utils").TSESTree.Expression} Expression
|
||||||
* @typedef {import("@typescript-eslint/types/dist/generated/ast-spec").JSXEmptyExpression } JSXEmptyExpression
|
* @typedef {import('@typescript-eslint/utils').TSESTree.JSXEmptyExpression } JSXEmptyExpression
|
||||||
* @typedef {import("@typescript-eslint/types/dist/generated/ast-spec").PrivateIdentifier } PrivateIdentifier
|
* @typedef {import('@typescript-eslint/utils').TSESTree.PrivateIdentifier } PrivateIdentifier
|
||||||
* @typedef {import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpressionComputedName } MemberExpressionComputedName
|
* @typedef {import('@typescript-eslint/utils').TSESTree.MemberExpressionComputedName } MemberExpressionComputedName
|
||||||
* @typedef {import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpressionNonComputedName } MemberExpressionNonComputedName
|
* @typedef {import('@typescript-eslint/utils').TSESTree.MemberExpressionNonComputedName } MemberExpressionNonComputedName
|
||||||
* @typedef {import('@typescript-eslint/types/dist/generated/ast-spec').Identifier} Identifier
|
* @typedef {import('@typescript-eslint/utils').TSESTree.Identifier} Identifier
|
||||||
*
|
*
|
||||||
* @typedef {import("@typescript-eslint/utils/dist/ts-eslint/Scope").Scope.Scope } Scope
|
* @typedef {import('@typescript-eslint/utils').TSESLint.Scope.Scope} Scope
|
||||||
* @typedef {import("@typescript-eslint/utils/dist/ts-eslint/Scope").Scope.Variable } Variable
|
* @typedef {import('@typescript-eslint/utils').TSESLint.Scope.Variable} Variable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const GRAFANA_E2E_PACKAGE_NAME = '@grafana/e2e-selectors';
|
const GRAFANA_E2E_PACKAGE_NAME = '@grafana/e2e-selectors';
|
||||||
@ -69,7 +69,7 @@ const rule = createRule({
|
|||||||
meta: {
|
meta: {
|
||||||
docs: {
|
docs: {
|
||||||
description: 'aria-label should not contain e2e selectors',
|
description: 'aria-label should not contain e2e selectors',
|
||||||
recommended: 'error',
|
// recommended: 'error',
|
||||||
},
|
},
|
||||||
messages: {
|
messages: {
|
||||||
useDataTestId: 'Use data-testid for E2E selectors instead of aria-label',
|
useDataTestId: 'Use data-testid for E2E selectors instead of aria-label',
|
||||||
@ -145,4 +145,6 @@ function findVariableInScope(initialScope, variableName) {
|
|||||||
|
|
||||||
scope = scope.upper;
|
scope = scope.upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -7,23 +7,20 @@ const borderRadiusRule = createRule({
|
|||||||
create(context) {
|
create(context) {
|
||||||
return {
|
return {
|
||||||
CallExpression(node) {
|
CallExpression(node) {
|
||||||
if (
|
if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'css') {
|
||||||
node.callee.type === AST_NODE_TYPES.Identifier &&
|
|
||||||
node.callee.name === 'css'
|
|
||||||
) {
|
|
||||||
const cssObjects = node.arguments.flatMap((node) => {
|
const cssObjects = node.arguments.flatMap((node) => {
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case AST_NODE_TYPES.ObjectExpression:
|
case AST_NODE_TYPES.ObjectExpression:
|
||||||
return [node];
|
return [node];
|
||||||
case AST_NODE_TYPES.ArrayExpression:
|
case AST_NODE_TYPES.ArrayExpression:
|
||||||
return node.elements.filter(v => v.type === AST_NODE_TYPES.ObjectExpression);
|
return node.elements.filter((v) => v?.type === AST_NODE_TYPES.ObjectExpression);
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const cssObject of cssObjects) {
|
for (const cssObject of cssObjects) {
|
||||||
if (cssObject.type === AST_NODE_TYPES.ObjectExpression) {
|
if (cssObject?.type === AST_NODE_TYPES.ObjectExpression) {
|
||||||
for (const property of cssObject.properties) {
|
for (const property of cssObject.properties) {
|
||||||
if (
|
if (
|
||||||
property.type === AST_NODE_TYPES.Property &&
|
property.type === AST_NODE_TYPES.Property &&
|
||||||
@ -48,7 +45,6 @@ const borderRadiusRule = createRule({
|
|||||||
type: 'problem',
|
type: 'problem',
|
||||||
docs: {
|
docs: {
|
||||||
description: 'Check if border-radius theme tokens are used',
|
description: 'Check if border-radius theme tokens are used',
|
||||||
recommended: false,
|
|
||||||
},
|
},
|
||||||
messages: {
|
messages: {
|
||||||
borderRadiusId: 'Prefer using theme.shape.radius tokens instead of literal values.',
|
borderRadiusId: 'Prefer using theme.shape.radius tokens instead of literal values.',
|
||||||
|
@ -12,8 +12,11 @@ const themeTokenUsage = createRule({
|
|||||||
const paths = [];
|
const paths = [];
|
||||||
let lastAncestor = null;
|
let lastAncestor = null;
|
||||||
for (const ancestor of ancestors) {
|
for (const ancestor of ancestors) {
|
||||||
if (ancestor.type === AST_NODE_TYPES.MemberExpression && ancestor.property.type === AST_NODE_TYPES.Identifier) {
|
if (
|
||||||
paths.push(ancestor.property.name)
|
ancestor.type === AST_NODE_TYPES.MemberExpression &&
|
||||||
|
ancestor.property.type === AST_NODE_TYPES.Identifier
|
||||||
|
) {
|
||||||
|
paths.push(ancestor.property.name);
|
||||||
lastAncestor = ancestor;
|
lastAncestor = ancestor;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -23,14 +26,14 @@ const themeTokenUsage = createRule({
|
|||||||
paths.unshift('theme');
|
paths.unshift('theme');
|
||||||
context.report({
|
context.report({
|
||||||
node: lastAncestor,
|
node: lastAncestor,
|
||||||
messageId: "themeTokenUsed",
|
messageId: 'themeTokenUsed',
|
||||||
data: {
|
data: {
|
||||||
identifier: paths.join('.')
|
identifier: paths.join('.'),
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
name: 'theme-token-usage',
|
name: 'theme-token-usage',
|
||||||
@ -38,7 +41,6 @@ const themeTokenUsage = createRule({
|
|||||||
type: 'problem',
|
type: 'problem',
|
||||||
docs: {
|
docs: {
|
||||||
description: 'Check for theme token usage',
|
description: 'Check for theme token usage',
|
||||||
recommended: false,
|
|
||||||
},
|
},
|
||||||
messages: {
|
messages: {
|
||||||
themeTokenUsed: '{{ identifier }}',
|
themeTokenUsed: '{{ identifier }}',
|
||||||
|
10
packages/grafana-eslint-rules/tsconfig.json
Normal file
10
packages/grafana-eslint-rules/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "Node16",
|
||||||
|
"moduleResolution": "Node16",
|
||||||
|
"declaration": false,
|
||||||
|
"allowJs": true,
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"extends": "@grafana/tsconfig"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user