Skip to content

Commit

Permalink
feat: add biomejs feature
Browse files Browse the repository at this point in the history
  • Loading branch information
liangling0628 committed Nov 25, 2024
1 parent 0e5d0e1 commit 7b34111
Show file tree
Hide file tree
Showing 99 changed files with 558 additions and 375 deletions.
74 changes: 74 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": false
},
"vcs": {
"enabled": true,
"clientKind": "git"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": {
"level": "off"
},
"noAssignInExpressions": "warn",
"noArrayIndexKey": "warn"
},
"style": {
"useSelfClosingElements": {
"fix": "safe",
"level": "warn"
},
"noUnusedTemplateLiteral": {
"fix": "safe",
"level": "error"
},
"noNonNullAssertion": "warn"
},
"complexity": {
"noBannedTypes": {
"fix": "safe",
"level": "error"
},
"noForEach": {
"level": "warn"
},
"useArrowFunction": {
"fix": "none",
"level": "warn"
}
},
"a11y": {
"useKeyWithMouseEvents": "off",
"useKeyWithClickEvents": "off",
"noSvgWithoutTitle": "off",
"useValidAnchor": "off"
}
}
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 120,
"attributePosition": "multiline"
},
"javascript": {
"jsxRuntime": "reactClassic",
"formatter": {
"quoteStyle": "single",
"jsxQuoteStyle": "single",
"quoteProperties": "asNeeded",
"trailingCommas": "es5",
"semicolons": "always",
"arrowParentheses": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false,
"attributePosition": "multiline"
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"packageManager": "[email protected]",
"devDependencies": {
"@babel/core": "^7.24.5",
"@biomejs/biome": "^1.9.4",
"@blueking/bkui-lint": "^0.0.3",
"@grafana/tsconfig": "1.3.0-rc1",
"@swc/core": "^1.4.17",
Expand Down
91 changes: 91 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/alert/.config/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@testing-library/jest-dom';
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
Object.defineProperty(global, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
Expand Down
2 changes: 1 addition & 1 deletion src/alert/.config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
*/

const path = require('path');
const path = require('node:path');
const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils');

module.exports = {
Expand Down
8 changes: 7 additions & 1 deletion src/alert/.config/jest/mocks/react-inlinesvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/;
const InlineSVG = ({ src }: { src: string }) => {
// testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`)
const testId = src.replace(SVG_FILE_NAME_REGEX, '$2');
return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />;
return (
<svg
xmlns='http://www.w3.org/2000/svg'
data-testid={testId}
viewBox='0 0 24 24'
/>
);
};

export default InlineSVG;
2 changes: 1 addition & 1 deletion src/alert/.config/jest/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* This utility function is useful in combination with jest `transformIgnorePatterns` config
* to transform specific packages (e.g.ES modules) in a projects node_modules folder.
*/
const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!.*(${moduleNames.join('|')})\/.*)`;
const nodeModulesToTransform = moduleNames => `node_modules\/(?!.*(${moduleNames.join('|')})\/.*)`;

// Array of known nested grafana package dependencies that only bundle an ESM version
const grafanaESModules = [
Expand Down
10 changes: 5 additions & 5 deletions src/alert/.config/webpack/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import process from 'process';
import os from 'os';
import path from 'path';
import fs from 'node:fs';
import process from 'node:process';
import os from 'node:os';
import path from 'node:path';
import { glob } from 'glob';
import { SOURCE_DIR } from './constants';

Expand Down Expand Up @@ -39,7 +39,7 @@ export async function getEntries(): Promise<Record<string, string>> {
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });

const plugins = await Promise.all(
pluginsJson.map((pluginJson) => {
pluginsJson.map(pluginJson => {
const folder = path.dirname(pluginJson);
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
})
Expand Down
20 changes: 10 additions & 10 deletions src/alert/.config/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import CopyWebpackPlugin from 'copy-webpack-plugin';
import LiveReloadPlugin from 'webpack-livereload-plugin';
import path from 'path';
import path from 'node:path';
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { Configuration } from 'webpack';
import type { Configuration } from 'webpack';

import { getPackageJson, getPluginJson, hasReadme, getEntries, isWSL } from './utils';
import { SOURCE_DIR, DIST_DIR } from './constants';
Expand Down Expand Up @@ -58,8 +58,8 @@ const config = async (env): Promise<Configuration> => {
// Mark legacy SDK imports as external if their name starts with the "grafana/" prefix
({ request }, callback) => {
const prefix = 'grafana/';
const hasPrefix = (request) => request.indexOf(prefix) === 0;
const stripPrefix = (request) => request.substr(prefix.length);
const hasPrefix = request => request.indexOf(prefix) === 0;
const stripPrefix = request => request.substr(prefix.length);

if (hasPrefix(request)) {
return callback(undefined, stripPrefix(request));
Expand Down Expand Up @@ -101,7 +101,7 @@ const config = async (env): Promise<Configuration> => {
{
loader: 'sass-loader',
options: {
additionalData: `$plugin-name: monitor-grafana-alert;`,
additionalData: '$plugin-name: monitor-grafana-alert;',
},
},
],
Expand Down Expand Up @@ -152,7 +152,7 @@ const config = async (env): Promise<Configuration> => {
generator: {
publicPath: `public/plugins/${pluginJson.id}/img/`,
outputPath: 'img/',
filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
filename: env.production ? '[hash][ext]' : '[file]',
},
},
{
Expand All @@ -161,17 +161,17 @@ const config = async (env): Promise<Configuration> => {
generator: {
publicPath: `public/plugins/${pluginJson.id}/fonts/`,
outputPath: 'fonts/',
filename: Boolean(env.production) ? '[hash][ext]' : '[name][ext]',
filename: env.production ? '[hash][ext]' : '[name][ext]',
},
},
],
},

output: {
clean: {
keep: new RegExp(`(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)`),
keep: /(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)/,
},
filename: `[name].js`,
filename: '[name].js',
path: path.resolve(process.cwd(), DIST_DIR),
publicPath: `public/plugins/${pluginJson.id}/`,
libraryTarget: 'amd',
Expand Down Expand Up @@ -215,7 +215,7 @@ const config = async (env): Promise<Configuration> => {
},
]),
new MiniCssExtractPlugin({
filename: `[name].css`,
filename: '[name].css',
chunkFilename: '[id].css',
}),
...(env.development
Expand Down
4 changes: 2 additions & 2 deletions src/alert/src/components/alert-condition-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class AlertConditionInput extends React.PureComponent<IProps, ISt
};
}
return item;
}),
})
);
}
/**
Expand Down Expand Up @@ -152,7 +152,7 @@ export default class AlertConditionInput extends React.PureComponent<IProps, ISt
};
}
return item;
}),
})
);
if (this.state.dimensionValueMap[v] || !v) return;
const data = await this.getDimensionValue(v);
Expand Down
3 changes: 2 additions & 1 deletion src/alert/src/components/alert-dimension-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import Select from 'antd/es/select';
import Tooltip from 'antd/es/tooltip';
import React from 'react';

import { type ICommonItem } from '../typings/metric';
import { LanguageContext } from '../utils/context';
import { t } from '../utils/utils';

import type { ICommonItem } from '../typings/metric';
const { Option } = Select;
export interface IDimensionInputProps {
agg_dimension: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/alert/src/components/editor-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Tooltip from 'antd/es/tooltip';
import React from 'react';

import { type MetricDetail } from '../typings/metric';
import type { MetricDetail } from '../typings/metric';
import { LanguageContext } from '../utils/context';
export interface IEditorFormProps {
metricList?: MetricDetail[];
Expand Down
Loading

0 comments on commit 7b34111

Please sign in to comment.