Skip to content

Commit eb86a21

Browse files
add eslint rules and run lint:fix(#445)
1 parent 617538f commit eb86a21

104 files changed

Lines changed: 901 additions & 898 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ packages/lezer-metricsql/src/parser.terms.js
3636
.vscode
3737
.npm
3838
.eslintcache
39+
tsconfig.tsbuildinfo
3940

4041
# Cypress
4142
cypress/report.json

eslint.config.mjs

Lines changed: 125 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import stylistic from '@stylistic/eslint-plugin';
2-
import { defineConfig } from 'eslint/config';
2+
import {defineConfig} from 'eslint/config';
33
import grafanaEslintConfig from '@grafana/eslint-config/flat.js';
44
import react from 'eslint-plugin-react';
55
import jest from 'eslint-plugin-jest';
@@ -8,136 +8,138 @@ import deprecation from 'eslint-plugin-deprecation';
88
import prettier from 'eslint-config-prettier';
99
import unusedImports from "eslint-plugin-unused-imports";
1010
import * as emotionPlugin from '@emotion/eslint-plugin';
11-
import { fixupPluginRules } from "@eslint/compat";
11+
import {fixupPluginRules} from "@eslint/compat";
1212
import importPlugin from 'eslint-plugin-import';
1313

1414
export default defineConfig([
15-
grafanaEslintConfig,
16-
prettier,
17-
{
18-
ignores: [
19-
'**/node_modules/**',
20-
'**/dist/**',
21-
'**/build/**',
22-
'**/coverage/**',
23-
'**/.yarn/**',
24-
'**/.cache/**',
25-
'**/.config/**',
26-
'**/vendor/**',
27-
'**/pkg/**',
28-
'**/plugins/**',
29-
'**/bin/**',
30-
'**/*.min.js',
31-
'**/packages/**',
32-
'.prettierrc.js',
33-
'webpack.config.ts',
34-
'jest.config.js',
35-
'jest-setup.js',
36-
],
37-
},
38-
{
39-
files: ['**/*.{ts,tsx,js,jsx}'],
40-
plugins: {
41-
'react': react,
42-
'jest': jest,
43-
'lodash': lodash,
44-
'deprecation': deprecation,
45-
'unused-imports': unusedImports,
46-
'@emotion': fixupPluginRules(emotionPlugin),
47-
'import': importPlugin,
48-
'@stylistic': stylistic,
49-
},
50-
languageOptions: {
51-
parserOptions: {
52-
ecmaVersion: 'latest',
53-
sourceType: 'module',
54-
ecmaFeatures: {
55-
jsx: true,
56-
},
57-
project: './tsconfig.json',
58-
},
59-
globals: {
60-
// Browser globals
61-
window: 'readonly',
62-
document: 'readonly',
63-
navigator: 'readonly',
64-
console: 'readonly',
65-
// Node globals
66-
process: 'readonly',
67-
__dirname: 'readonly',
68-
__filename: 'readonly',
69-
module: 'readonly',
70-
require: 'readonly',
71-
},
15+
grafanaEslintConfig,
16+
prettier,
17+
{
18+
ignores: [
19+
'**/node_modules/**',
20+
'**/dist/**',
21+
'**/build/**',
22+
'**/coverage/**',
23+
'**/.yarn/**',
24+
'**/.cache/**',
25+
'**/.config/**',
26+
'**/vendor/**',
27+
'**/pkg/**',
28+
'**/plugins/**',
29+
'**/bin/**',
30+
'**/*.min.js',
31+
'**/packages/**',
32+
'.prettierrc.js',
33+
'webpack.config.ts',
34+
'jest.config.js',
35+
'jest-setup.js',
36+
],
37+
},
38+
{
39+
files: ['**/*.{ts,tsx,js,jsx}'],
40+
plugins: {
41+
'react': react,
42+
'jest': jest,
43+
'lodash': lodash,
44+
'deprecation': deprecation,
45+
'unused-imports': unusedImports,
46+
'@emotion': fixupPluginRules(emotionPlugin),
47+
'import': importPlugin,
48+
'@stylistic': stylistic,
49+
},
50+
languageOptions: {
51+
parserOptions: {
52+
ecmaVersion: 'latest',
53+
sourceType: 'module',
54+
ecmaFeatures: {
55+
jsx: true,
7256
},
57+
project: './tsconfig.json',
58+
},
59+
globals: {
60+
// Browser globals
61+
window: 'readonly',
62+
document: 'readonly',
63+
navigator: 'readonly',
64+
console: 'readonly',
65+
// Node globals
66+
process: 'readonly',
67+
__dirname: 'readonly',
68+
__filename: 'readonly',
69+
module: 'readonly',
70+
require: 'readonly',
71+
},
72+
},
7373

7474

75-
rules: {
76-
'react-hooks/rules-of-hooks': 'error',
77-
'react-hooks/exhaustive-deps': 'warn',
78-
'@typescript-eslint/no-explicit-any': 'warn',
79-
"unused-imports/no-unused-imports": "error",
80-
'@typescript-eslint/no-unused-vars': ['warn', {
81-
argsIgnorePattern: '^_',
82-
varsIgnorePattern: '^_'
83-
}],
84-
'no-console': ['warn', { allow: ['warn', 'error'] }],
85-
"react/prop-types": "off",
86-
"@emotion/jsx-import": "error",
87-
"object-curly-spacing": [2, "always"],
88-
"lodash/import-scope": [2, "member"],
89-
"jest/no-focused-tests": "error",
90-
"@typescript-eslint/array-type": 0,
91-
"no-useless-escape": 0,
92-
"no-prototype-builtins": 0,
93-
'@stylistic/indent': ['error', 2, {
94-
'SwitchCase': 1,
95-
'FunctionDeclaration': { 'parameters': 'first' },
96-
'FunctionExpression': { 'parameters': 'first' },
97-
'CallExpression': { 'arguments': 1 },
98-
'ObjectExpression': 'first',
99-
'ignoredNodes': [
100-
'TSTypeAnnotation *',
101-
],
102-
}],
103-
'@stylistic/jsx-max-props-per-line': ['error', {
104-
maximum: 1,
105-
when: 'multiline'
106-
}],
107-
'@stylistic/jsx-first-prop-new-line': ['error', 'multiline-multiprop'],
108-
'@stylistic/jsx-closing-bracket-location': ['error', 'tag-aligned'],
109-
"import/order": [
110-
"error",
75+
rules: {
76+
'react-hooks/rules-of-hooks': 'error',
77+
'react-hooks/exhaustive-deps': 'warn',
78+
'@typescript-eslint/no-explicit-any': 'warn',
79+
"unused-imports/no-unused-imports": "error",
80+
'@typescript-eslint/no-unused-vars': ['warn', {
81+
argsIgnorePattern: '^_',
82+
varsIgnorePattern: '^_'
83+
}],
84+
'no-console': ['warn', {allow: ['warn', 'error']}],
85+
"react/prop-types": "off",
86+
"@emotion/jsx-import": "error",
87+
"object-curly-spacing": [2, "always"],
88+
"lodash/import-scope": [2, "member"],
89+
"jest/no-focused-tests": "error",
90+
"@typescript-eslint/array-type": 0,
91+
"no-useless-escape": 0,
92+
"no-prototype-builtins": 0,
93+
'@stylistic/indent': ['error', 2, {
94+
'SwitchCase': 1,
95+
'FunctionDeclaration': {'parameters': 'first'},
96+
'FunctionExpression': {'parameters': 'first'},
97+
'CallExpression': {'arguments': 1},
98+
'ObjectExpression': 'first',
99+
'ignoredNodes': [
100+
'TSTypeAnnotation *',
101+
],
102+
}],
103+
'@stylistic/jsx-max-props-per-line': ['error', {
104+
maximum: 1,
105+
when: 'multiline'
106+
}],
107+
'@stylistic/jsx-first-prop-new-line': ['error', 'multiline-multiprop'],
108+
'@stylistic/jsx-closing-bracket-location': ['error', 'tag-aligned'],
109+
"import/order": [
110+
"error",
111+
{
112+
"groups": [["builtin", "external"], "internal", "parent", "sibling", "index"],
113+
'pathGroups': [
111114
{
112-
"groups": [["builtin", "external"], "internal", "parent", "sibling", "index"],
113-
'pathGroups': [
114-
{
115-
pattern: '@grafana/**',
116-
group: 'external',
117-
position: 'after'
118-
}
119-
],
120-
'pathGroupsExcludedImportTypes': ['react', 'react-dom'],
121-
"newlines-between": "always",
122-
"alphabetize": { "order": "asc" }
115+
pattern: '@grafana/**',
116+
group: 'external',
117+
position: 'after'
123118
}
124119
],
120+
'pathGroupsExcludedImportTypes': ['react', 'react-dom'],
121+
"newlines-between": "always",
122+
"alphabetize": {"order": "asc"}
123+
}
124+
],
125+
'react/jsx-tag-spacing': ['error', {beforeSelfClosing: 'always'}],
126+
'jsx-quotes': ['error', 'prefer-single'],
127+
quotes: ['error', 'single', {avoidEscape: true}],
125128

126-
// Use typescript's no-redeclare for compatibility with overrides
127-
"no-redeclare": "off",
128-
"@typescript-eslint/no-redeclare": ["error"]
129-
},
130-
},
129+
// Use typescript's no-redeclare for compatibility with overrides
130+
"no-redeclare": "off",
131+
"@typescript-eslint/no-redeclare": ["error"]
132+
},
133+
},
131134

132-
{
133-
files: ['**/*.test.{ts,tsx,js,jsx}', '**/__tests__/**'],
134-
plugins: {
135-
jest,
136-
},
137-
rules: {
138-
...jest.configs.recommended.rules,
139-
'@typescript-eslint/no-explicit-any': 'off',
140-
},
141-
},
142-
]
143-
);
135+
{
136+
files: ['**/*.test.{ts,tsx,js,jsx}', '**/__tests__/**'],
137+
plugins: {
138+
jest,
139+
},
140+
rules: {
141+
...jest.configs.recommended.rules,
142+
'@typescript-eslint/no-explicit-any': 'off',
143+
},
144+
},
145+
]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test:coverage": "jest --collectCoverage",
1212
"test:ci": "jest --passWithNoTests --maxWorkers 4",
1313
"lint": "eslint --cache .",
14-
"lint:fix": "yarn run lint --fix && prettier --write --list-different .",
14+
"lint:fix": "yarn run lint --fix",
1515
"server": "docker compose up --build",
1616
"preinstall": "cd packages/lezer-metricsql && yarn install && cd ../..",
1717
"postinstall": "yarn upgrade lezer-metricsql",

src/components/Annotations/AnnotationQueryEditor.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AutoSizeInput, LegacyForms } from '@grafana/ui';
66
const { Input } = LegacyForms;
77
import { PromQueryCodeEditor } from '../../querybuilder/components/PromQueryCodeEditor';
88
import { PromQuery } from '../../types';
9-
import { EditorField, EditorRows, EditorRow, Space, EditorSwitch } from "../QueryEditor";
9+
import { EditorField, EditorRows, EditorRow, Space, EditorSwitch } from '../QueryEditor';
1010
import { PromQueryEditorProps } from '../types';
1111

1212
type Props = PromQueryEditorProps & {
@@ -40,7 +40,7 @@ export function AnnotationQueryEditor(props: Props) {
4040
<Space v={0.5} />
4141
<EditorRow>
4242
<EditorField
43-
label="Min step"
43+
label='Min step'
4444
tooltip={
4545
<>
4646
An additional lower limit for the step parameter of the Prometheus query and for the{' '}
@@ -49,50 +49,50 @@ export function AnnotationQueryEditor(props: Props) {
4949
}
5050
>
5151
<AutoSizeInput
52-
type="text"
53-
aria-label="Set lower limit for the step parameter"
52+
type='text'
53+
aria-label='Set lower limit for the step parameter'
5454
placeholder={'auto'}
5555
minWidth={10}
5656
defaultValue={query.interval}
5757
onCommitChange={(ev) => handlerChangeAnnotation(ev.currentTarget.value, 'step')}
5858
/>
5959
</EditorField>
6060
<EditorField
61-
label="Title"
61+
label='Title'
6262
tooltip={
6363
'Use either the name or a pattern. For example, {{instance}} is replaced with label value for the label instance.'
6464
}
6565
>
6666
<Input
67-
type="text"
68-
placeholder="{{alertname}}"
67+
type='text'
68+
placeholder='{{alertname}}'
6969
value={annotation.titleFormat}
7070
onChange={(ev) => handlerChangeAnnotation(ev.currentTarget.value, 'titleFormat')}
7171
/>
7272
</EditorField>
73-
<EditorField label="Tags">
73+
<EditorField label='Tags'>
7474
<Input
75-
type="text"
76-
placeholder="label1,label2"
75+
type='text'
76+
placeholder='label1,label2'
7777
value={annotation.tagKeys}
7878
onChange={(ev) => handlerChangeAnnotation(ev.currentTarget.value, 'tagKeys')}
7979
/>
8080
</EditorField>
8181
<EditorField
82-
label="Text"
82+
label='Text'
8383
tooltip={
8484
'Use either the name or a pattern. For example, {{instance}} is replaced with label value for the label instance.'
8585
}
8686
>
8787
<Input
88-
type="text"
89-
placeholder="{{instance}}"
88+
type='text'
89+
placeholder='{{instance}}'
9090
value={annotation.textFormat}
9191
onChange={(ev) => handlerChangeAnnotation(ev.currentTarget.value, 'textFormat')}
9292
/>
9393
</EditorField>
9494
<EditorField
95-
label="Series value as timestamp"
95+
label='Series value as timestamp'
9696
tooltip={
9797
'The unit of timestamp is milliseconds. If the unit of the series value is seconds, multiply its range vector by 1000.'
9898
}

src/components/PrettifyQuery.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { render, screen, act } from '@testing-library/react';
22
import React from 'react';
33

4-
import { BackendSrvRequest } from "@grafana/runtime";
4+
import { BackendSrvRequest } from '@grafana/runtime';
55

6-
import { PrometheusDatasource } from "../datasource";
6+
import { PrometheusDatasource } from '../datasource';
77

88
import PrettifyQuery from './PrettifyQuery';
99

@@ -80,7 +80,7 @@ const datasource = {
8080
}
8181
} as unknown as PrometheusDatasource;
8282

83-
describe("Prettyfied Query", () => {
83+
describe('Prettyfied Query', () => {
8484
testQueries.forEach(async ({ name, got, want }) => {
8585
it(`should prettify the query ${name}`, async () => {
8686

0 commit comments

Comments
 (0)