-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
253 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import path from "path" | ||
|
||
export const filenames = { | ||
index: "index.js", | ||
prettier: "eslint-config-prettier.js", | ||
} | ||
export const rootPath = path.resolve(import.meta.dir, "..") | ||
|
||
export const extraRulesToDisable = [ | ||
"simple-import-sort/imports", | ||
// Not being added for some reason, TODO check it and fix it | ||
"no-new-symbol", | ||
// https://github.com/biomejs/biome/pull/1801 | ||
"no-delete-var", | ||
"no-return-assign", | ||
"no-useless-computed-key", | ||
"unicorn/no-static-only-class", | ||
"unicorn/no-typeof-undefined", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { JSDOM } from "jsdom" | ||
|
||
export const getRecommendedBiomeRules = async (): Promise<Array<string>> => { | ||
const response = await fetch("https://biomejs.dev/linter/rules/") | ||
const html = await response.text() | ||
|
||
const dom = new JSDOM(html) | ||
const document = dom.window.document | ||
|
||
const rows = document.querySelectorAll("table tr") | ||
|
||
const recommendedRules = [...rows] | ||
.map((row) => { | ||
const cells = row.querySelectorAll("td") | ||
const rowTexts = [...cells].map((cell) => cell.textContent?.trim() ?? "") | ||
|
||
return rowTexts | ||
}) | ||
.filter((rowTexts) => rowTexts[2]?.includes("✅")) | ||
.map((recommendedRowTexts) => recommendedRowTexts[0] ?? "") | ||
|
||
return recommendedRules | ||
} | ||
|
||
type Equivalency = { eslint: string; biome: string } | ||
|
||
export const getEquivalentRules = async (): Promise<Array<Equivalency>> => { | ||
const response = await fetch("https://biomejs.dev/linter/rules-sources/") | ||
const html = await response.text() | ||
|
||
const dom = new JSDOM(html) | ||
const document = dom.window.document | ||
|
||
const tables = document.querySelectorAll("table") | ||
|
||
const rowsTexts = [...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") | ||
|
||
if (!pluginName) throw new Error("Invalid plugin") | ||
|
||
const prefix = ["Clippy", "ESLint"].includes(pluginName) | ||
? "" | ||
: `${pluginName}/` | ||
|
||
const rows = [...table.querySelectorAll("tr")].filter((tr) => | ||
tr.querySelector("td"), | ||
) | ||
|
||
const rowsTexts = rows.map((row) => { | ||
const rowTexts = [...row.querySelectorAll("td, td")].map( | ||
(cell) => cell.textContent?.trim() ?? "", | ||
) | ||
|
||
rowTexts[0] = prefix + rowTexts[0] | ||
// Sometimes they have `${biomeRuleName} (inspired)`. We get just the first word. | ||
rowTexts[1] = rowTexts[1]?.split(" ")[0] ?? "" | ||
|
||
return rowTexts | ||
}) | ||
|
||
return rowsTexts | ||
}) | ||
|
||
const equivalentRules: Array<Equivalency> = rowsTexts.flatMap((rowTexts) => ({ | ||
eslint: rowTexts[0] ?? "", | ||
biome: rowTexts[1] ?? "", | ||
})) | ||
|
||
return equivalentRules | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import fs from "fs" | ||
import { filenames } from "./consts.js" | ||
|
||
export const createPrettierFile = async () => { | ||
const response = await fetch( | ||
"https://raw.githubusercontent.com/prettier/eslint-config-prettier/main/index.js", | ||
) | ||
const attribution = `/** | ||
* eslint-config-prettier © 2017-2023 Simon Lydell and contributors | ||
* https://github.com/prettier/eslint-config-prettier | ||
* | ||
* This code is licensed under the MIT License (MIT). | ||
* | ||
* File automatically created by scripts/index.ts. | ||
*/ | ||
` | ||
const text = attribution + (await response.text()) | ||
|
||
fs.writeFileSync(filenames.prettier, text) | ||
} |
Oops, something went wrong.