diff --git a/.config/.eslintrc b/.config/.eslintrc index 15ae260..adb4846 100644 --- a/.config/.eslintrc +++ b/.config/.eslintrc @@ -4,7 +4,7 @@ * In order to extend the configuration follow the steps in * https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-eslint-config */ - { +{ "extends": ["@grafana/eslint-config"], "root": true, "rules": { diff --git a/.config/.prettierrc.js b/.config/.prettierrc.js index 66a76ec..bf506f5 100644 --- a/.config/.prettierrc.js +++ b/.config/.prettierrc.js @@ -5,12 +5,12 @@ */ module.exports = { - "endOfLine": "auto", - "printWidth": 120, - "trailingComma": "es5", - "semi": true, - "jsxSingleQuote": false, - "singleQuote": true, - "useTabs": false, - "tabWidth": 2 -}; \ No newline at end of file + endOfLine: 'auto', + printWidth: 120, + trailingComma: 'es5', + semi: true, + jsxSingleQuote: false, + singleQuote: true, + useTabs: false, + tabWidth: 2, +}; diff --git a/.config/webpack/utils.ts b/.config/webpack/utils.ts index 144ea19..07eea6e 100644 --- a/.config/webpack/utils.ts +++ b/.config/webpack/utils.ts @@ -2,11 +2,9 @@ import fs from 'fs'; import process from 'process'; import os from 'os'; import path from 'path'; -import util from 'util'; import { glob } from 'glob'; import { SOURCE_DIR } from './constants'; - export function isWSL() { if (process.platform !== 'linux') { return false; @@ -21,7 +19,7 @@ export function isWSL() { } catch { return false; } -} +} export function getPackageJson() { return require(path.resolve(process.cwd(), 'package.json')); @@ -40,7 +38,8 @@ export function hasReadme() { export async function getEntries(): Promise> { const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true }); - const plugins = await Promise.all(pluginsJson.map((pluginJson) => { + const plugins = await Promise.all( + pluginsJson.map((pluginJson) => { const folder = path.dirname(pluginJson); return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true }); }) diff --git a/.config/webpack/webpack.config.ts b/.config/webpack/webpack.config.ts index f1e1470..1c2739e 100644 --- a/.config/webpack/webpack.config.ts +++ b/.config/webpack/webpack.config.ts @@ -8,12 +8,13 @@ import CopyWebpackPlugin from 'copy-webpack-plugin'; import ESLintPlugin from 'eslint-webpack-plugin'; import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; +import LiveReloadPlugin from 'webpack-livereload-plugin'; import path from 'path'; import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin'; import { Configuration } from 'webpack'; -import LiveReloadPlugin from 'webpack-livereload-plugin'; -import { DIST_DIR, SOURCE_DIR } from './constants'; -import { getEntries, getPackageJson, getPluginJson, hasReadme, isWSL } from './utils'; + +import { getPackageJson, getPluginJson, hasReadme, getEntries, isWSL } from './utils'; +import { SOURCE_DIR, DIST_DIR } from './constants'; const pluginJson = getPluginJson(); diff --git a/.eslintrc b/.eslintrc index 4c801b9..bd53992 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,20 +1,17 @@ { - "extends": "./.config/.eslintrc", + "extends": ["./.config/.eslintrc", "@volkovlabs/eslint-config"], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": "latest", "project": "./tsconfig.json", "sourceType": "module" }, - "plugins": ["deprecation"], - "rules": { - "deprecation/deprecation": ["error"], - "sort-imports": [ - "error", - { - "ignoreCase": true, - "ignoreDeclarationSort": true + "overrides": [ + { + "files": ["**/*.test.tsx", "**/*.test.ts"], + "rules": { + "@typescript-eslint/no-explicit-any": "off" } - ] - } + } + ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef0cb4..c90d389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Update to Grafana 10.1.5 (#88) - Update to Grafana 10.3.1 (#90) +- Update ESLint configuration and refactoring (#91) ## 3.2.0 (2023-10-04) diff --git a/package-lock.json b/package-lock.json index 30c6e8b..c909e31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "@types/react-router-dom": "^5.3.3", "@types/webpack-env": "^1.18.2", "@typescript-eslint/eslint-plugin": "^6.7.5", + "@volkovlabs/eslint-config": "^1.2.2", "copy-webpack-plugin": "^11.0.0", "css-loader": "^6.8.1", "eslint-plugin-deprecation": "^2.0.0", @@ -6481,7 +6482,6 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.5.tgz", "integrity": "sha512-bIZVSGx2UME/lmhLcjdVc7ePBwn7CLqKarUBL4me1C5feOd663liTGjMBGVcGr+BhnSLeP4SgwdvNnnkbIdkCw==", "dev": true, - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "6.7.5", "@typescript-eslint/types": "6.7.5", @@ -6704,6 +6704,21 @@ "dev": true, "peer": true }, + "node_modules/@volkovlabs/eslint-config": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@volkovlabs/eslint-config/-/eslint-config-1.3.0.tgz", + "integrity": "sha512-xrzF9aj1tP/LEiKYJJSfEKiaIVm7mBhYFdAVaYqejL/NIgcRPDhP8EzL120rggDEaGc5yO/zy82cFTfE/3UiNw==", + "dev": true, + "dependencies": { + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "eslint-plugin-deprecation": "^2.0.0", + "eslint-plugin-simple-import-sort": "^10.0.0" + }, + "peerDependencies": { + "eslint": "^8.0.0" + } + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", @@ -10262,6 +10277,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/eslint-plugin-simple-import-sort": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-10.0.0.tgz", + "integrity": "sha512-AeTvO9UCMSNzIHRkg8S6c3RPy5YEwKWSQPx3DYghLedo2ZQxowPFLGDN1AZ2evfg6r6mjBSZSLxLFsWSu3acsw==", + "dev": true, + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", diff --git a/package.json b/package.json index d866a4f..ebe41cc 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@types/react-router-dom": "^5.3.3", "@types/webpack-env": "^1.18.2", "@typescript-eslint/eslint-plugin": "^6.7.5", + "@volkovlabs/eslint-config": "^1.2.2", "copy-webpack-plugin": "^11.0.0", "css-loader": "^6.8.1", "eslint-plugin-deprecation": "^2.0.0", diff --git a/src/components/App/App.test.tsx b/src/components/App/App.test.tsx index 10571e2..1bf3956 100644 --- a/src/components/App/App.test.tsx +++ b/src/components/App/App.test.tsx @@ -1,8 +1,9 @@ -import React from 'react'; -import { BrowserRouter } from 'react-router-dom'; import { AppPluginMeta, PluginType } from '@grafana/data'; import { render, screen } from '@testing-library/react'; -import { AppInfo, TestIds } from '../../constants'; +import React from 'react'; +import { BrowserRouter } from 'react-router-dom'; + +import { APP_INFO, TEST_IDS } from '../../constants'; import { App } from './App'; /** @@ -41,12 +42,12 @@ describe('App', () => { it('Should render community page', async () => { render( - + ); - expect(screen.queryByTestId(TestIds.development.root)).not.toBeInTheDocument(); - expect(screen.getByTestId(TestIds.community.root)).toBeInTheDocument(); + expect(screen.queryByTestId(TEST_IDS.development.root)).not.toBeInTheDocument(); + expect(screen.getByTestId(TEST_IDS.community.root)).toBeInTheDocument(); }); }); diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index c111799f..a3beebb 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -1,7 +1,8 @@ +import { AppRootProps } from '@grafana/data'; import React from 'react'; import { Route, Switch } from 'react-router-dom'; -import { AppRootProps } from '@grafana/data'; -import { Routes } from '../../constants'; + +import { APP_ROUTES } from '../../constants'; import { AppSettings } from '../../types'; import { Community } from '../Community'; import { Development } from '../Development'; @@ -17,7 +18,7 @@ interface Props extends AppRootProps {} export const App: React.FC = () => { return ( - + ); diff --git a/src/components/Community/Community.tsx b/src/components/Community/Community.tsx index fdeb5cf..0562ff6 100644 --- a/src/components/Community/Community.tsx +++ b/src/components/Community/Community.tsx @@ -1,14 +1,15 @@ -import React from 'react'; import { PluginPage, PluginPageProps } from '@grafana/runtime'; -import { TestIds } from '../../constants'; +import React from 'react'; + +import { TEST_IDS } from '../../constants'; import { - ApacheECharts, + ApacheEcharts, Base64Image, Calendar, DataManipulation, DynamicText, - GrafanaAPI, - RSSAtom, + GrafanaApi, + RssAtom, Static, Variable, } from '../Plugins'; @@ -24,14 +25,14 @@ interface Props extends PluginPageProps {} export const Community: React.FC = () => { return ( -
- +
+ - - + +
diff --git a/src/components/Config/Config.test.tsx b/src/components/Config/Config.test.tsx index f3a2a96..658c6be 100644 --- a/src/components/Config/Config.test.tsx +++ b/src/components/Config/Config.test.tsx @@ -1,6 +1,7 @@ -import React from 'react'; import { render, screen } from '@testing-library/react'; -import { TestIds } from '../../constants'; +import React from 'react'; + +import { TEST_IDS } from '../../constants'; import { Config } from './Config'; /* @@ -23,6 +24,6 @@ describe('Config', () => { render(); - expect(screen.getByTestId(TestIds.config.root)).toBeInTheDocument(); + expect(screen.getByTestId(TEST_IDS.config.root)).toBeInTheDocument(); }); }); diff --git a/src/components/Config/Config.tsx b/src/components/Config/Config.tsx index b018d25..eaba5aa 100644 --- a/src/components/Config/Config.tsx +++ b/src/components/Config/Config.tsx @@ -1,7 +1,8 @@ -import React from 'react'; import { AppPluginMeta, PluginConfigPageProps } from '@grafana/data'; import { FieldSet } from '@grafana/ui'; -import { AppInfo, TestIds } from '../../constants'; +import React from 'react'; + +import { APP_INFO, TEST_IDS } from '../../constants'; import { AppSettings } from '../../types'; /** @@ -14,8 +15,8 @@ interface Props extends PluginConfigPageProps> {} */ export const Config: React.FC = () => { return ( -
-

{AppInfo.name}

+
+

{APP_INFO.name}

The Volkov Labs App includes Docker image and App plugin with information about Volkov Labs supported Grafana plugins. diff --git a/src/components/Development/Development.tsx b/src/components/Development/Development.tsx index 61bd6e9..d1bc11d 100644 --- a/src/components/Development/Development.tsx +++ b/src/components/Development/Development.tsx @@ -1,6 +1,7 @@ -import React from 'react'; import { PluginPage, PluginPageProps } from '@grafana/runtime'; -import { TestIds } from '../../constants'; +import React from 'react'; + +import { TEST_IDS } from '../../constants'; import { Balena, Environment } from '../Plugins'; /** @@ -14,7 +15,7 @@ interface Props extends PluginPageProps {} export const Development: React.FC = () => { return ( -

+
diff --git a/src/components/Plugins/ApacheECharts.tsx b/src/components/Plugins/ApacheECharts.tsx index 7a6b726..6f13796 100644 --- a/src/components/Plugins/ApacheECharts.tsx +++ b/src/components/Plugins/ApacheECharts.tsx @@ -1,10 +1,10 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Apache ECharts */ -export const ApacheECharts: React.FC = () => { +export const ApacheEcharts: React.FC = () => { return ( Apache ECharts Panel diff --git a/src/components/Plugins/Balena.tsx b/src/components/Plugins/Balena.tsx index 05d9546..f1e792d 100644 --- a/src/components/Plugins/Balena.tsx +++ b/src/components/Plugins/Balena.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Balena App diff --git a/src/components/Plugins/Base64Image.tsx b/src/components/Plugins/Base64Image.tsx index e722bf3..010350d 100644 --- a/src/components/Plugins/Base64Image.tsx +++ b/src/components/Plugins/Base64Image.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Base64 diff --git a/src/components/Plugins/Calendar.tsx b/src/components/Plugins/Calendar.tsx index 296651e..023d51f 100644 --- a/src/components/Plugins/Calendar.tsx +++ b/src/components/Plugins/Calendar.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Calendar diff --git a/src/components/Plugins/DataManipulation.tsx b/src/components/Plugins/DataManipulation.tsx index 4bbcefd..d28a334 100644 --- a/src/components/Plugins/DataManipulation.tsx +++ b/src/components/Plugins/DataManipulation.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Data Manipulation diff --git a/src/components/Plugins/DynamicText.tsx b/src/components/Plugins/DynamicText.tsx index af150b3..349d7cf 100644 --- a/src/components/Plugins/DynamicText.tsx +++ b/src/components/Plugins/DynamicText.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Dynamic Text diff --git a/src/components/Plugins/Environment.tsx b/src/components/Plugins/Environment.tsx index df73de4..659ea2b 100644 --- a/src/components/Plugins/Environment.tsx +++ b/src/components/Plugins/Environment.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Environment Data Source diff --git a/src/components/Plugins/GrafanaAPI.tsx b/src/components/Plugins/GrafanaAPI.tsx index 2a1773a..cdfe47b 100644 --- a/src/components/Plugins/GrafanaAPI.tsx +++ b/src/components/Plugins/GrafanaAPI.tsx @@ -1,10 +1,10 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Grafana HTTP API */ -export const GrafanaAPI: React.FC = () => { +export const GrafanaApi: React.FC = () => { return ( Grafana HTTP API Data Source diff --git a/src/components/Plugins/RSSAtom.tsx b/src/components/Plugins/RSSAtom.tsx index d8c20f5..84d8068 100644 --- a/src/components/Plugins/RSSAtom.tsx +++ b/src/components/Plugins/RSSAtom.tsx @@ -1,10 +1,10 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * RSS/Atom */ -export const RSSAtom: React.FC = () => { +export const RssAtom: React.FC = () => { return ( RSS/Atom Data Source diff --git a/src/components/Plugins/Static.tsx b/src/components/Plugins/Static.tsx index 5498535..8a8502e 100644 --- a/src/components/Plugins/Static.tsx +++ b/src/components/Plugins/Static.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Static diff --git a/src/components/Plugins/Variable.tsx b/src/components/Plugins/Variable.tsx index 4d6cc77..cf79a01 100644 --- a/src/components/Plugins/Variable.tsx +++ b/src/components/Plugins/Variable.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import { Card, LinkButton, TagList } from '@grafana/ui'; +import React from 'react'; /** * Variable diff --git a/src/constants/app.ts b/src/constants/app.ts index 86ebaa2..0af01fd 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -1,7 +1,7 @@ /** * App Information */ -export const AppInfo = { +export const APP_INFO = { name: 'Volkov Labs', root: '/a/volkovlabs-app', }; @@ -9,7 +9,7 @@ export const AppInfo = { /** * Routes */ -export const Routes = { - community: `${AppInfo.root}`, - development: `${AppInfo.root}/development`, +export const APP_ROUTES = { + community: `${APP_INFO.root}`, + development: `${APP_INFO.root}/development`, }; diff --git a/src/constants/tests.ts b/src/constants/tests.ts index da0f041..cd19e40 100644 --- a/src/constants/tests.ts +++ b/src/constants/tests.ts @@ -1,7 +1,7 @@ /** * Tests Identifiers */ -export const TestIds = { +export const TEST_IDS = { config: { root: 'data-testid config', }, diff --git a/src/module.test.ts b/src/module.test.ts index 21d39ea..1d40913 100644 --- a/src/module.test.ts +++ b/src/module.test.ts @@ -1,4 +1,5 @@ import { AppPlugin } from '@grafana/data'; + import { plugin } from './module'; /* diff --git a/src/module.ts b/src/module.ts index 89e9693..52616e8 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,4 +1,5 @@ import { AppPlugin } from '@grafana/data'; + import { App, Config } from './components'; import { AppSettings } from './types'; diff --git a/src/types.ts b/src/types.ts index f2cf6fe..a98117c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,7 +6,7 @@ export interface AppSettings {} /** * SVG */ -export interface SVGProps extends React.HTMLAttributes { +export interface SvgProps extends React.HTMLAttributes { /** * Size *