-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy patheslintBiome.mjs
46 lines (40 loc) · 1.53 KB
/
eslintBiome.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { load } from 'cheerio'
import fetch from 'node-fetch'
const URL = 'https://biomejs.dev/linter/rules-sources'
/**
* Usage:
* ```bash
* node scripts/eslintBiome.mjs > tmp.json
* # copy tmp.json to eslint.config.mjs
*/
;(async () => {
try {
const response = await fetch(URL)
if (!response.ok) {
throw new Error(`Failed to fetch URL: ${response.statusText}`)
}
const html = await response.text()
const $ = load(html)
let str = '{\n'
$('h3').each((_, section) => {
let sectionName = $(section).text().trim().toLowerCase().replace(/ /g, '-') + '/'
if (sectionName === 'clippy/') return // Not ESlint stuff
// Rename section as required in configuration
if (sectionName === 'eslint/') sectionName = ''
if (sectionName === 'eslint-plugin-react/') sectionName = 'react/'
if (sectionName === 'eslint-plugin-react-hooks/') sectionName = 'react-hooks/'
if (sectionName === 'eslint-plugin-react-refresh/') sectionName = 'react-refresh/'
if (sectionName === 'typescript-eslint/') sectionName = '@typescript-eslint/'
const rulesList = $(section).parent().next('table').find('tbody').children('tr')
for (const rule of rulesList) {
const [eslintRule, biomeRule] = $(rule).children('td')
const row = ` "${sectionName}${$(eslintRule).text()}": "off", // ${$(biomeRule).text()}`
str += row + '\n'
}
})
str += '}'
console.log(str)
} catch (error) {
console.error('Error fetching or processing data:', error.message)
}
})()