Skip to content

Commit

Permalink
feat: biome lint (#4853)
Browse files Browse the repository at this point in the history
This commit changes our linter/formatter to biome (https://biomejs.dev/)
Causing our prehook to run almost instantly, and our "yarn lint" task to
run in sub 100ms.

Some trade-offs:
* Biome isn't quite as well established as ESLint
* Are we ready to install a different vscode plugin (the biome plugin)
instead of the prettier plugin


The configuration set for biome also has a set of recommended rules,
this is turned on by default, in order to get to something that was
mergeable I have turned off a couple the rules we seemed to violate the
most, that we also explicitly told eslint to ignore.
  • Loading branch information
Christopher Kolstad authored Sep 29, 2023
1 parent fbc571d commit 6673d13
Show file tree
Hide file tree
Showing 97 changed files with 430 additions and 1,593 deletions.
15 changes: 0 additions & 15 deletions .eslintignore

This file was deleted.

59 changes: 0 additions & 59 deletions .eslintrc

This file was deleted.

96 changes: 96 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "https://biomejs.dev/schemas/1.2.2/schema.json",
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"performance": {
"noDelete": "off"
},
"correctness": {
"noUnsafeOptionalChaining": "off"
},
"complexity": {
"noBannedTypes": "off",
"noUselessConstructor": "off",
"useOptionalChain": "warn",
"noStaticOnlyClass": "off"
},
"style": {
"noNonNullAssertion": "off",
"noInferrableTypes": "off",
"noUnusedTemplateLiteral": "off",
"useSingleVarDeclarator": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noExtraNonNullAssertion": "off",
"noRedeclare": "off"
}
},
"ignore": [
"node_modules",
"docker",
"bundle.js",
"website/blog",
"website/build",
"website/core",
"website/docs",
"website/i18n/*.js",
"website/pages",
"website/translated_docs",
"website",
"setupJest.js",
"frontend",
"dist",
"src/migrations/*.js",
"src/test/examples/*.json",
"website/**/*.js",
"coverage"
]
},
"organizeImports": {
"enabled": false
},
"formatter": {
"indentStyle": "space",
"ignore": [
"node_modules",
"docker",
"bundle.js",
"website/blog",
"website/build",
"website/core",
"website/docs",
"website/i18n/*.js",
"website/pages",
"website/translated_docs",
"website",
"setupJest.js",
"frontend",
"dist",
"src/migrations/*.js",
"src/migrations/*.json",
"src/test/examples/*.json",
"website/**/*.js",
"coverage",
".eslintrc",
".eslintignore",
"package.json"
],
"indentSize": 4
},
"javascript": {
"formatter": {
"semicolons": "always",
"quoteStyle": "single",
"jsxQuoteStyle": "single",
"indentSize": 4
}
},
"json": {
"formatter": {
"indentSize": 2
}
}
}
32 changes: 4 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"prestart:dev": "yarn run clean",
"start:dev": "TZ=UTC NODE_ENV=development tsc-watch --strictNullChecks false --onSuccess \"node dist/server-dev.js\"",
"db-migrate": "db-migrate --migrations-dir ./src/migrations",
"lint": "eslint ./src",
"lint": "biome check src",
"local:package": "del-cli --force build && mkdir build && cp -r dist docs CHANGELOG.md LICENSE README.md package.json build",
"prebuild:watch": "yarn run clean",
"build:watch": "tsc -w --strictNullChecks false",
Expand Down Expand Up @@ -168,6 +168,7 @@
"@apidevtools/swagger-parser": "10.1.0",
"@babel/core": "7.22.17",
"@swc/core": "1.3.88",
"@biomejs/biome": "1.2.2",
"@swc/jest": "0.2.29",
"@types/bcryptjs": "2.4.3",
"@types/cors": "2.8.14",
Expand All @@ -190,20 +191,10 @@
"@types/supertest": "2.0.12",
"@types/type-is": "1.6.4",
"@types/uuid": "9.0.3",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"concurrently": "^8.0.1",
"copyfiles": "2.4.1",
"coveralls": "3.1.1",
"del-cli": "5.1.0",
"eslint": "^8.38.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "8.10.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-regexp": "^1.14.0",
"faker": "5.5.3",
"fast-check": "3.13.0",
"fetch-mock": "9.11.0",
Expand All @@ -213,7 +204,6 @@
"lint-staged": "13.2.3",
"nock": "13.3.3",
"openapi-enforcer": "1.22.3",
"prettier": "2.8.1",
"proxyquire": "2.1.3",
"source-map-support": "0.5.21",
"superagent": "8.1.2",
Expand Down Expand Up @@ -241,24 +231,10 @@
},
"lint-staged": {
"*.{js,ts}": [
"eslint --fix"
"biome check --apply"
],
"*.{json,yaml,md}": [
"prettier --write"
]
},
"prettier": {
"proseWrap": "never",
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all",
"overrides": [
{
"files": "*.{json,yaml,yml,md}",
"options": {
"tabWidth": 2
}
}
"biome format --write"
]
}
}
8 changes: 4 additions & 4 deletions scripts/npm-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ function isPrerelease(version) {
return arr && arr.length > 0;
}

if(isPrerelease(version)){
console.log('beta')
}else if(semver.gt(version, latestUnleashVersion)) {
if (isPrerelease(version)) {
console.log('beta');
} else if (semver.gt(version, latestUnleashVersion)) {
console.log('latest');
} else {
console.log('previous');
}
}
6 changes: 3 additions & 3 deletions src/lib/addons/datadog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test('Should call datadog webhook for archived toggle with project info', async
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
});

test(`Should call datadog webhook for toggled environment`, async () => {
test('Should call datadog webhook for toggled environment', async () => {
const addon = new DatadogAddon({
getLogger: noLogger,
unleashUrl: 'http://some-url.com',
Expand Down Expand Up @@ -169,7 +169,7 @@ test(`Should call datadog webhook for toggled environment`, async () => {
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
});

test(`Should include customHeaders in headers when calling service`, async () => {
test('Should include customHeaders in headers when calling service', async () => {
const addon = new DatadogAddon({
getLogger: noLogger,
unleashUrl: 'http://some-url.com',
Expand Down Expand Up @@ -205,7 +205,7 @@ test(`Should include customHeaders in headers when calling service`, async () =>
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
});

test(`Should not include source_type_name when included in the config`, async () => {
test('Should not include source_type_name when included in the config', async () => {
const addon = new DatadogAddon({
getLogger: noLogger,
unleashUrl: 'http://some-url.com',
Expand Down
3 changes: 1 addition & 2 deletions src/lib/addons/datadog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export default class DatadogAddon extends Addon {
}

const { tags: eventTags } = event;
const tags =
eventTags && eventTags.map((tag) => `${tag.type}:${tag.value}`);
const tags = eventTags?.map((tag) => `${tag.type}:${tag.value}`);
const body: DDRequestBody = {
text: text,
title: 'Unleash notification update',
Expand Down
5 changes: 2 additions & 3 deletions src/lib/addons/feature-event-formatter-md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ const testCases: [string, IEvent, string][] = [
].map(
([operator, display]) =>
<[string, IEvent, string]>[
'when default strategy updated with numeric constraint ' +
operator,
`when default strategy updated with numeric constraint ${operator}`,
{
id: 39,
type: FEATURE_STRATEGY_UPDATE,
Expand Down Expand Up @@ -504,7 +503,7 @@ const testCases: [string, IEvent, string][] = [
];

testCases.forEach(([description, event, expected]) =>
test('Should format specialised text for events ' + description, () => {
test(`Should format specialised text for events ${description}`, () => {
const formatter = new FeatureEventFormatterMd('unleashUrl');
const actual = formatter.format(event);
expect(actual).toBe(expected);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/addons/feature-event-formatter-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export interface FeatureEventFormatter {
format: (event: IEvent) => string;
featureLink: (event: IEvent) => string;
}

export enum LinkStyle {
SLACK,
MD,
SLACK = 0,
MD = 1,
}

export class FeatureEventFormatterMd implements FeatureEventFormatter {
Expand Down Expand Up @@ -254,10 +253,11 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter {
SEMVER_LT: 'is a SemVer less than',
};
const formatConstraint = (constraint: IConstraint) => {
const val = constraint.hasOwnProperty('value')
const val = Object.hasOwn(constraint, 'value')
? constraint.value
: `(${constraint.values.join(',')})`;
const operator = constraintOperatorDescriptions.hasOwnProperty(
const operator = Object.hasOwn(
constraintOperatorDescriptions,
constraint.operator,
)
? constraintOperatorDescriptions[constraint.operator]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function getApp(

const baseUriPath = config.server.baseUriPath || '';
const publicFolder = config.publicFolder || findPublicFolder();
let indexHTML = await loadIndexHTML(config, publicFolder);
const indexHTML = await loadIndexHTML(config, publicFolder);

app.set('trust proxy', true);
app.disable('x-powered-by');
Expand Down
Loading

0 comments on commit 6673d13

Please sign in to comment.