Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBrahma committed Dec 22, 2023
1 parent 84f6a0a commit 99f579b
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

bun i
4 changes: 4 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

bun i
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.2.0

- Added `"simple-import-sort/imports": "off"`.
- Added some tests for improved maturity of this package

## 1.1.0

- Fix missing plugin name in the start of the rule name.
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"formatter": {
"semicolons": "asNeeded"
}
}
},
"files": { "ignore": ["index.js"] }
}
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
"default-case-last": "off",
"default-param-last": "off",
"dot-notation": "off",
eqeqeq: "off",
"eqeqeq": "off",
"for-direction": "off",
"getter-return": "off",
"no-async-promise-executor": "off",
Expand Down Expand Up @@ -133,5 +133,6 @@ module.exports = {
"unicorn/no-typeof-undefined": "off",
"unicorn/no-useless-switch-case": "off",
"unicorn/prefer-array-flat-map": "off",
},
"simple-import-sort/imports": "off",
}
}
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "eslint-config-biome",
"version": "1.1.0",
"version": "1.2.0",
"description": "Disables ESLint rules that have a recommended and equivalent Biome rule",
"main": "index.js",
"scripts": {
"start": "bun --watch run scripts/index.ts",
"pre-commit": "bun test && bun format",
"format": "biome check --apply-unsafe .",
"tsw": "tsc --watch --noEmit",
"typecheck": "tsc --noEmit",
"pre-commit": "bun typecheck && bun test && bun format",
"prepare": "husky install",
"format": "biome check --apply ."
"test:watch": "bun test --watch",
"watch": "bun --watch run scripts/index.ts",
"start": "bun run scripts/index.ts"
},
"repository": "SrBrahma/eslint-config-biome",
"keywords": [
Expand Down
34 changes: 34 additions & 0 deletions scripts/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from "bun:test"
import fs from "fs"
import path from "path"
import { spawnSync } from "bun"

const rootPath = path.resolve(import.meta.dir, "..")
const indexJsPath = path.resolve(rootPath, "index.js")

test("index.js exists", () => {
expect(fs.existsSync(indexJsPath)).toBeTrue()
})

test("index.js is a valid file and can be used by eslint", () => {
// In the root there is a .eslintrc that uses the index.js in the extends.
expect(
spawnSync(["bunx", "eslint", "./scripts/index.ts"], {
cwd: rootPath,
}).success,
).toBeTrue()
})

test("index.js has rules from different plugins and includes extra rules", () => {
const rulesToCheck = [
"no-unsafe-optional-chaining",
"@typescript-eslint/no-extra-non-null-assertion",
"jsx-a11y/html-has-lang",
"react/no-children-prop",
"unicorn/no-instanceof-array",
"simple-import-sort/imports",
]
const indexJsContent = fs.readFileSync(indexJsPath, "utf-8")

expect(rulesToCheck.every((rule) => indexJsContent.includes(rule))).toBeTrue()
})
16 changes: 10 additions & 6 deletions scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Code based on https://github.com/biomejs/biome/discussions/3#discussioncomment-7910787. Thanks, Dani Guardiola!

import fs from "fs"
import { JSDOM } from "jsdom"

// Code based on https://github.com/biomejs/biome/discussions/3#discussioncomment-7910787. Thanks, Dani Guardiola!

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 (proof of concept for now)
*/
Expand Down Expand Up @@ -75,13 +76,16 @@ ${rules.map((rule) => ` "${rule}": "off",`).join("\n")}
`

fs.writeFileSync("index.js", text)

// Lint it! This is mainly to remove non required quotes. We could do some regex check but whatever!
Bun.spawnSync(["bunx", "biome", "check", "--apply-unsafe", "index.js"])
}

const extraRulesToDisable = ["simple-import-sort/imports"]

const main = async () => {
writeFile(await getEslintEquivalentRules())
const rules = [...(await getEslintEquivalentRules()), ...extraRulesToDisable]

writeFile(rules)

console.log("Generated index.js!")
}

await main()

0 comments on commit 99f579b

Please sign in to comment.