Skip to content

Commit

Permalink
feat: basic ts rules migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 18, 2023
1 parent b39834c commit 8cc6daf
Show file tree
Hide file tree
Showing 40 changed files with 4,190 additions and 194 deletions.
19 changes: 17 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
"no-template-curly-in-string": "off",
"no-mixed-operators": "off",
"max-statements-per-line": "off",
"no-cond-assign": "off"
}
"no-cond-assign": "off",

"eslint-comments/no-unused-enable": "off",
"jsdoc/check-param-names": "off",
"unicorn/prefer-number-properties": "off",

"@typescript-eslint/no-require-import": "off",
"@typescript-eslint/no-var-requires": "off"
},
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@typescript-eslint/no-require-imports": "off"
}
}
]
}
5 changes: 4 additions & 1 deletion docs/.vitepress/components/RuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { packages } from '../../../packages/metadata'
<div>
<div v-for="pkg of packages" :key="pkg.name">
<template v-if="pkg.rules.length">
<h3><code>{{ pkg.name }}</code></h3>
<h3 :id="pkg.shortId">
<code>{{ pkg.name }}</code>
<a class="header-anchor" :href="`#${pkg.shortId}`" :aria-label="`Permalink to ${pkg.name}`" />
</h3>
<table>
<RuleItem
v-for="rule of pkg.rules"
Expand Down
24 changes: 23 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import MarkdownItContainer from 'markdown-it-container'
import { packages } from '../../packages/metadata'
import vite from './vite.config'

const mainPackages = packages.filter(p => p.rules.length)

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: 'ESLint Stylistic',
Expand Down Expand Up @@ -62,9 +64,18 @@ export default defineConfig({

sidebar: Object.assign(
// @ts-expect-error anyway
...packages.map((pkg) => {
...mainPackages.map((pkg) => {
return {
[`/rules/${pkg.shortId}`]: [
{
text: 'Other Packages',
items: mainPackages
.filter(i => i.name !== pkg.name)
.map(pkg => ({
text: pkg.name,
link: `/packages#${pkg.shortId}`,
})),
},
{
text: pkg.name,
items: pkg.rules.map((rule): DefaultTheme.SidebarItem => ({
Expand All @@ -75,6 +86,17 @@ export default defineConfig({
],
}
}),
{
'/': [
{
text: 'Packages',
items: mainPackages.map(pkg => ({
text: pkg.name,
link: `/packages#${pkg.shortId}`,
})),
},
],
},
),

socialLinks: [
Expand Down
20 changes: 15 additions & 5 deletions docs/.vitepress/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import UnoCSS from 'unocss/vite'
import Components from 'unplugin-vue-components/vite'
import graymatter from 'gray-matter'
import { packages } from '../../packages/metadata'
import rules from '../../packages/eslint-plugin-stylistic-js/rules'

export default defineConfig({
plugins: [
Expand Down Expand Up @@ -47,15 +46,26 @@ function MarkdownTransform(): Plugin {
content,
} = graymatter(code)

content = content
.replaceAll(
`eslint ${rule.name}:`,
`eslint ${rule.ruleId}:`,
)
.replace(
/> 🛑.*(\n>.*)*/,
'',
)
.replaceAll(
'@typescript-eslint/',
'@stylistic/ts/',
)

content = [
`<a href="/packages#${pkg.name}" class="font-mono no-underline!">${rule.ruleId.slice(0, -rule.name.length)}</a>`,
`<h1 class="font-mono mt--4">${rule.name}</h1>`,
'',
'\n',
content.replaceAll(
`eslint ${rule.name}:`,
`eslint ${rule.ruleId}:`,
),
content,
].join('\n')

return graymatter.stringify(content, { data })
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
"@antfu/utils": "^0.7.6",
"@rollup/plugin-commonjs": "^25.0.4",
"@types/eslint": "^8.44.2",
"@types/fs-extra": "^11.0.2",
"@types/node": "^20.6.2",
"bumpp": "^9.2.0",
"eslint": "^8.49.0",
"esno": "^0.17.0",
"fast-glob": "^3.3.1",
"fs-extra": "^11.1.1",
"lint-staged": "^14.0.1",
"pnpm": "^8.7.6",
"rimraf": "^5.0.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin-js/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
Copyright (c) 2023-PRESENT eslint-stylistic and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions packages/eslint-plugin-ts/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2019 typescript-eslint and other contributors
Copyright (c) 2023-PRESENT eslint-stylistic and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 20 additions & 1 deletion packages/eslint-plugin-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,24 @@
"main": "./dist/index.js",
"files": [
"dist"
]
],
"scripts": {
"build": "rimraf dist && rollup --config=rollup.config.mts --configPlugin=rollup-plugin-esbuild",
"dev": "rollup --config=rollup.config.mts --configPlugin=rollup-plugin-esbuild --watch",
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"eslint": "*",
"typescript": "*"
},
"dependencies": {
"@typescript-eslint/scope-manager": "^6.7.0",
"@typescript-eslint/type-utils": "^6.7.0",
"@typescript-eslint/utils": "^6.7.0",
"graphemer": "^1.4.0",
"semver": "^7.5.4"
},
"devDependencies": {
"@typescript-eslint/rule-tester": "^6.7.0"
}
}
35 changes: 35 additions & 0 deletions packages/eslint-plugin-ts/rollup.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fs from 'node:fs/promises'
import { basename, dirname } from 'node:path'
import { defineConfig } from 'rollup'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'

const pkg = JSON.parse(await fs.readFile(new URL('./package.json', import.meta.url), 'utf-8'))

export default defineConfig({
input: 'src/index.ts',
output: [
{
dir: 'dist',
format: 'cjs',
manualChunks(id) {
if (id.includes('rules')) {
const name = basename(dirname(id))
if (name !== 'rules')
return name
}
},
chunkFileNames: '[name].js',
},
],
plugins: [
esbuild(),
commonjs(),
],
external: [
...Object.keys(pkg.dependencies || []),
...Object.keys(pkg.peerDependencies || []),
'eslint/package.json',
'@typescript-eslint/utils/ast-utils',
],
})
5 changes: 3 additions & 2 deletions packages/eslint-plugin-ts/rules.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# eslint-plugin-stylistic-ts
# @stylistic/eslint-plugin-ts

| Rule ID | Description | Fixable | Recommended |
| --- | --- | --- | --- |
| --- | --- | --- | --- |
| [`@stylistic/ts/semi`](./rules/semi) | Require or disallow semicolons instead of ASI || |
3 changes: 0 additions & 3 deletions packages/eslint-plugin-ts/rules/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/eslint-plugin-ts/rules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import semi from './semi/semi'

export default {
semi,
}
12 changes: 12 additions & 0 deletions packages/eslint-plugin-ts/rules/semi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
description: 'Require or disallow semicolons instead of ASI.'
---

> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/semi** for documentation.
This rule extends the base [`eslint/semi`](https://eslint.org/docs/rules/semi) rule.
It adds support for TypeScript features that require semicolons.

See also the [`@typescript-eslint/member-delimiter-style`](member-delimiter-style.md) rule, which allows you to specify the delimiter for `type` and `interface` members.
Loading

0 comments on commit 8cc6daf

Please sign in to comment.