Skip to content

Commit

Permalink
1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Fantauzzi committed Apr 24, 2024
1 parent 84d2108 commit 532b75e
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 45 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 1.7.1

- Updated Biome to 1.7.1; added the following disables:

```json
"no-eval": "off",
"no-global-assign": "off",
"no-lone-blocks": "off",
"no-misleading-character-class": "off",
"no-unneeded-ternary": "off",
"no-use-before-define": "off",
"@mysticatea/eslint-plugin/no-this-in-static": "off",
"@typescript-eslint/consistent-type-exports": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/no-import-type-side-effects": "off",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/prefer-function-type": "off",
"jest/max-nested-describe": "off",
"jest/no-duplicate-hooks": "off",
"jest/no-export": "off",
"jest/no-focused-tests": "off",
"react/jsx-key": "off",
"unicorn/no-thenable": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-number-properties": "off",
```

## 1.5.3

Expand Down
Binary file modified bun.lockb
Binary file not shown.
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
"eqeqeq": "off",
"for-direction": "off",
"getter-return": "off",
"match_str_case_mismatch": "off",
"no-async-promise-executor": "off",
"no-case-declarations": "off",
"no-class-assign": "off",
Expand All @@ -33,16 +32,20 @@ module.exports = {
"no-empty": "off",
"no-empty-character-class": "off",
"no-empty-pattern": "off",
"no-eval": "off",
"no-ex-assign": "off",
"no-extra-boolean-cast": "off",
"no-extra-label": "off",
"no-fallthrough": "off",
"no-func-assign": "off",
"no-global-assign": "off",
"no-import-assign": "off",
"no-inner-declarations": "off",
"no-label-var": "off",
"no-labels": "off",
"no-lone-blocks": "off",
"no-loss-of-precision": "off",
"no-misleading-character-class": "off",
"no-new-native-nonconstructor": "off",
"no-new-symbol": "off",
"no-nonoctal-decimal-escape": "off",
Expand All @@ -59,11 +62,13 @@ module.exports = {
"no-shadow-restricted-names": "off",
"no-sparse-array": "off",
"no-this-before-super": "off",
"no-unneeded-ternary": "off",
"no-unreachable": "off",
"no-unsafe-finally": "off",
"no-unsafe-negation": "off",
"no-unsafe-optional-chaining": "off",
"no-unused-labels": "off",
"no-use-before-define": "off",
"no-useless-catch": "off",
"no-useless-computed-key": "off",
"no-useless-constructor": "off",
Expand All @@ -81,31 +86,42 @@ module.exports = {
"require-yield": "off",
"use-isnan": "off",
"valid-typeof": "off",
"@mysticatea/eslint-plugin/no-this-in-static": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-exports": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/default-param-last": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/no-dupe-class-members": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extra-non-null-assertion": "off",
"@typescript-eslint/no-extraneous-class": "off",
"@typescript-eslint/no-import-type-side-effects": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/no-loss-of-precision": "off",
"@typescript-eslint/no-misused-new": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-redeclare": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/no-unnecessary-type-constraint": "off",
"@typescript-eslint/no-unsafe-declaration-merging": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-useless-constructor": "off",
"@typescript-eslint/no-useless-empty-export": "off",
"@typescript-eslint/no-useless-template-literals": "off",
"@typescript-eslint/prefer-as-const": "off",
"@typescript-eslint/prefer-enum-initializers": "off",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/prefer-literal-enum-member": "off",
"@typescript-eslint/prefer-namespace-keyword": "off",
"@typescript-eslint/prefer-optional-chain": "off",
"jest/max-nested-describe": "off",
"jest/no-duplicate-hooks": "off",
"jest/no-export": "off",
"jest/no-focused-tests": "off",
"jsx-a11y/alt-text": "off",
"jsx-a11y/anchor-has-content": "off",
"jsx-a11y/anchor-is-valid": "off",
Expand All @@ -132,8 +148,8 @@ module.exports = {
"jsx-a11y/role-has-required-aria-props": "off",
"jsx-a11y/scope": "off",
"jsx-a11y/tabindex-no-positive": "off",
"mysticates/no-this-in-static": "off",
"react/button-has-type": "off",
"react/jsx-key": "off",
"react/jsx-no-comment-textnodes": "off",
"react/jsx-no-duplicate-props": "off",
"react/jsx-no-target-blank": "off",
Expand All @@ -149,8 +165,11 @@ module.exports = {
"unicorn/no-array-for-each": "off",
"unicorn/no-instanceof-array": "off",
"unicorn/no-static-only-class": "off",
"unicorn/no-thenable": "off",
"unicorn/no-typeof-undefined": "off",
"unicorn/no-useless-switch-case": "off",
"unicorn/prefer-array-flat-map": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-number-properties": "off",
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-biome",
"version": "1.5.3",
"version": "1.7.1",
"description": "Disables ESLint rules that have a recommended and equivalent Biome rule",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -30,11 +30,11 @@
"license": "MIT",
"files": ["index.js", "eslint-config-prettier.js"],
"devDependencies": {
"@biomejs/biome": "^1.5.0",
"@biomejs/biome": "^1.7.1",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/bun": "^1.0.0",
"@types/jsdom": "^21.1.6",
"eslint-config-gev": "^3.10.5",
"eslint-config-gev": "4.3.0",
"husky": "^8.0.1",
"jsdom": "^23.0.1",
"typescript": "^5.3.3"
Expand Down
4 changes: 2 additions & 2 deletions scripts/consts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from "path"
import path from "node:path"

export const filenames = {
index: "index.js",
prettier: "eslint-config-prettier.js",
}
export const rootPath = path.resolve(import.meta.dir, "..")
export const rootPath = path.resolve(__dirname, "..")

export const extraRulesToDisable = [
"simple-import-sort/imports",
Expand Down
29 changes: 25 additions & 4 deletions scripts/fetch.ts → scripts/fetchFromDocs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { JSDOM } from "jsdom"

export const getRecommendedBiomeRules = async (): Promise<Array<string>> => {
export const fetchRecommendedBiomeRulesFromDocs = async (): Promise<
Array<string>
> => {
const response = await fetch("https://biomejs.dev/linter/rules/")
const html = await response.text()

Expand All @@ -24,7 +26,9 @@ export const getRecommendedBiomeRules = async (): Promise<Array<string>> => {

type Equivalency = { eslint: string; biome: string }

export const getEquivalentRules = async (): Promise<Array<Equivalency>> => {
const pluginBlacklist = ["Clippy"]

const fetchEquivalentRulesFromDocs = async (): Promise<Array<Equivalency>> => {
const response = await fetch("https://biomejs.dev/linter/rules-sources/")
const html = await response.text()

Expand All @@ -33,17 +37,20 @@ export const getEquivalentRules = async (): Promise<Array<Equivalency>> => {

const tables = document.querySelectorAll("table")

const rowsTexts = [...tables].flatMap((table) => {
const rowsTexts: Array<Array<string>> = [...tables].flatMap((table) => {
const tableHeaders = Array.from(table.querySelectorAll("th")).map(
(th) => th.textContent?.trim() ?? "",
)

const pluginName = tableHeaders[0]
?.split(" ")[0]
?.replace("eslint-plugin-", "")
?.replace("typescript", "@typescript-eslint")
?.replace("typescript-eslint", "@typescript-eslint")

if (!pluginName) throw new Error("Invalid plugin")

if (pluginBlacklist.includes(pluginName)) return [[]]

const prefix = ["Clippy", "ESLint"].includes(pluginName)
? ""
: `${pluginName}/`
Expand Down Expand Up @@ -74,3 +81,17 @@ export const getEquivalentRules = async (): Promise<Array<Equivalency>> => {

return equivalentRules
}

export const getEquivalentRulesFromDocs = async (): Promise<Array<string>> => {
const recommendedBiomeRules = await fetchRecommendedBiomeRulesFromDocs()
const equivalentRules = await fetchEquivalentRulesFromDocs()

return recommendedBiomeRules
.map(
(biomeRule) =>
equivalentRules.find(
(equivalentRule) => equivalentRule.biome === biomeRule,
)?.eslint,
)
.filter(Boolean) as Array<string>
}
59 changes: 59 additions & 0 deletions scripts/fetchFromGithub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { JSDOM } from "jsdom"

const getTdString = (row: Element, column: number) =>
(
row.querySelector(`td:nth-child(${column})`) as HTMLTableCellElement
).textContent?.trim()

type Plugin = { id: string; prefix: string }

/** Returns the ESLint rules for the equivalent Biome's rules that are recommended */
const getEslintEquivalentRulesForPlugin = (
plugin: Plugin,
document: Document,
): Array<string> => {
const table = (
document.querySelector(`#user-content-${plugin.id}`)?.parentNode as Element
).nextElementSibling as HTMLTableElement | null

if (!table) throw new Error(`Missing table for plugin ${plugin.id}`)

const rows = Array.from(table.querySelectorAll("tbody > tr"))

const eslintRules: Array<string> = []

rows.forEach((row) => {
const eslintRule = getTdString(row, 1)
const biomeRule = getTdString(row, 3)
const isBiomeRecommended = getTdString(row, 4)?.includes("✅")

if (eslintRule && biomeRule && isBiomeRecommended) {
eslintRules.push(plugin.prefix + eslintRule)
}
})

return eslintRules
}

export const getEslintEquivalentRulesFromGithub = async (): Promise<
Array<string>
> => {
const plugins: Array<{ id: string; prefix: string }> = [
{ id: "eslint", prefix: "" },
{ id: "typescript-eslint", prefix: "@typescript-eslint/" },
{ id: "eslint-plugin-jest", prefix: "jest/" },
{ id: "eslint-plugin-jsx-a11y", prefix: "jsx-a11y/" },
{ id: "eslint-plugin-react", prefix: "react/" },
{ id: "eslint-plugin-react-hooks", prefix: "react-hooks/" },
{ id: "eslint-plugin-unicorn", prefix: "unicorn/" },
]

const response = await fetch("https://github.com/biomejs/biome/discussions/3")
const text = await response.text()
const dom = new JSDOM(text)
const document = dom.window.document

return plugins.flatMap((plugin) =>
getEslintEquivalentRulesForPlugin(plugin, document),
)
}
21 changes: 16 additions & 5 deletions scripts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */

import { expect, test } from "bun:test"
import fs from "fs"
import path from "path"
import fs from "node:fs"
import path from "node:path"
import { spawnSync } from "bun"

const rootPath = path.resolve(import.meta.dir, "..")
const rootPath = path.resolve(__dirname, "..")
const indexPath = path.resolve(rootPath, "index.js")
const prettierPath = path.resolve(rootPath, "eslint-config-prettier.js")
const indexContent = fs.readFileSync(indexPath, "utf-8")
const disabledRules = Object.keys(
(require(indexPath) as { rules: Record<string, string> }).rules,
)
const prettierContent = fs.readFileSync(prettierPath, "utf-8")

test("index.js is a valid file and can be used by eslint", () => {
Expand All @@ -28,7 +33,8 @@ test("index.js has rules from different plugins and includes extra rules", () =>
"simple-import-sort/imports",
]

expect(rulesToCheck.every((rule) => indexContent.includes(rule))).toBeTrue()
expect(disabledRules).toEqual(expect.arrayContaining(rulesToCheck))
expect(disabledRules.length).toBeGreaterThan(150) // 165 last time
})

test("TS extensions should be added to index.js", () => {
Expand All @@ -37,10 +43,15 @@ test("TS extensions should be added to index.js", () => {
"@typescript-eslint/default-param-last",
]

expect(rulesToCheck.every((rule) => indexContent.includes(rule))).toBeTrue()
expect(disabledRules).toEqual(expect.arrayContaining(rulesToCheck))
})

test("eslint-config-prettier is used and is valid", () => {
expect(indexContent).toContain('extends: ["./eslint-config-prettier.js"],')
expect(prettierContent).toContain('"react/jsx-indent": "off"')
})

test("doesnt include clippy rules", () => {
expect(disabledRules).not.toContain("if_not_else")
expect(disabledRules).not.toContain("eq_op")
})
31 changes: 13 additions & 18 deletions scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
/** Attribution for eslint-config-prettier is available at the ATTRIBUTION.md and in the eslint-config-prettier.js. */

import { extraRulesToDisable, filenames } from "./consts.js"
import { getEquivalentRules, getRecommendedBiomeRules } from "./fetch.js"
import { createPrettierFile } from "./prettier.js"
import { getJsBaseRules, getTsExtensionsForRules } from "./tsExtensions.js"
import { sortRules, writeFile } from "./utils.js"
import { extraRulesToDisable, filenames } from "./consts"
import { getEquivalentRulesFromDocs } from "./fetchFromDocs"
import { getEslintEquivalentRulesFromGithub } from "./fetchFromGithub.js"
import { createPrettierFile } from "./prettier"
import { getJsBaseRules, getTsExtensionsForRules } from "./tsExtensions"
import { sortRules, writeFile } from "./utils"

const main = async () => {
const recommendedBiomeRules = await getRecommendedBiomeRules()
const equivalentRules = await getEquivalentRules()

const eslintRulesToDisable = recommendedBiomeRules
.map(
(biomeRule) =>
equivalentRules.find(
(equivalentRule) => equivalentRule.biome === biomeRule,
)?.eslint,
)
.filter(Boolean) as Array<string>
const rules = [
...(await getEquivalentRulesFromDocs()),
...extraRulesToDisable,
...(await getEslintEquivalentRulesFromGithub()),
]

const rules = [...eslintRulesToDisable, ...extraRulesToDisable]
const rulesWithTsExtends = [
...rules,
...getJsBaseRules(rules),
...getTsExtensionsForRules(rules),
]

const rulesNoDuplicates = [...new Set(rulesWithTsExtends)]

writeFile(sortRules(rulesNoDuplicates))
Expand All @@ -33,4 +28,4 @@ const main = async () => {
console.log(`Generated ${filenames.index} & ${filenames.prettier}!`)
}

await main()
main()
4 changes: 0 additions & 4 deletions scripts/package.json

This file was deleted.

Loading

0 comments on commit 532b75e

Please sign in to comment.