Skip to content

Commit

Permalink
feat!: upgrade eslint plugin, require eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 16, 2024
1 parent a202654 commit cc3e1b1
Show file tree
Hide file tree
Showing 16 changed files with 5,843 additions and 3,089 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

11 changes: 0 additions & 11 deletions .eslintrc

This file was deleted.

50 changes: 49 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
{
"cSpell.enabled": false,
"grammarly.autoActivate": false
"grammarly.autoActivate": false,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

<!-- @case-police-ignore -->

- Git**H**ub, not *Github*
- Type**S**cript, not *Typescript*
- **m**acOS, not *MacOS*
- **VS C**ode, not *Vscode*
- Git**H**ub, not _Github_
- Type**S**cript, not _Typescript_
- **m**acOS, not _MacOS_
- **VS C**ode, not _Vscode_
- [...](./packages/case-police/dict)

Make the case correct, PLEASE!
Expand Down Expand Up @@ -57,15 +57,15 @@ npx case-police "**/*.md" path/to/file.html

## CLI Options

| Options | Description |
| --- | --- |
| `[...globs]` | Files or glob to be checked, if not provided, all the text files will be check |
| `--fix` | Rewrite changes to file |
| `-d, --dict <path>` | Custom dictionary JSON, will be merged with original dict |
| `-p, --presets <presets>` | Filter the default [presets](./packages/case-police/dict), comma separated |
| `--no-default` | Disable the default dictionary |
| `--disable <rules>` | Disable rules, comma separated |
| `--ignore <globs>` | Files or globs to be ignore, comma separated |
| Options | Description |
| ------------------------- | ------------------------------------------------------------------------------ |
| `[...globs]` | Files or glob to be checked, if not provided, all the text files will be check |
| `--fix` | Rewrite changes to file |
| `-d, --dict <path>` | Custom dictionary JSON, will be merged with original dict |
| `-p, --presets <presets>` | Filter the default [presets](./packages/case-police/dict), comma separated |
| `--no-default` | Disable the default dictionary |
| `--disable <rules>` | Disable rules, comma separated |
| `--ignore <globs>` | Files or globs to be ignore, comma separated |

### Ignores

Expand Down
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import antfu from '@antfu/eslint-config'

export default antfu(
{
ignores: ['**/fixture/**'],
formatters: true,
},
{
files: ['dict/*.json'],
rules: {
'jsonc/sort-keys': 'error',
},
},
)
47 changes: 25 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "module",
"version": "0.6.1",
"private": true,
"packageManager": "pnpm@8.4.0",
"packageManager": "pnpm@9.7.1",
"scripts": {
"build": "pnpm -r run build",
"dev": "pnpm -r run dev",
Expand All @@ -13,29 +13,32 @@
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@antfu/eslint-config": "^0.38.5",
"@antfu/ni": "^0.21.3",
"@babel/types": "^7.21.5",
"@types/fs-extra": "^11.0.1",
"@types/minimist": "^1.2.2",
"@types/node": "^18.16.3",
"bumpp": "^9.1.0",
"eslint": "^8.39.0",
"@antfu/eslint-config": "^2.25.2",
"@antfu/ni": "^0.22.4",
"@babel/types": "^7.25.2",
"@types/fs-extra": "^11.0.4",
"@types/minimist": "^1.2.5",
"@types/node": "^22.3.0",
"@typescript-eslint/parser": "^8.1.0",
"bumpp": "^9.5.1",
"eslint": "^9.9.0",
"eslint-plugin-case-police": "workspace:*",
"esno": "^0.16.3",
"fast-glob": "^3.2.12",
"fs-extra": "^11.1.1",
"is-binary-path": "^2.1.0",
"is-text-path": "^2.0.0",
"eslint-plugin-format": "^0.1.2",
"eslint-vitest-rule-tester": "^0.6.1",
"esno": "^4.7.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"is-binary-path": "^3.0.0",
"is-text-path": "^3.0.0",
"minimist": "^1.2.8",
"p-limit": "^4.0.0",
"p-limit": "^6.1.0",
"parse-gitignore": "^2.0.0",
"picocolors": "^1.0.0",
"pnpm": "^8.4.0",
"rimraf": "^5.0.0",
"typescript": "^5.0.4",
"unbuild": "^1.2.1",
"vite": "^4.3.4",
"vitest": "^0.30.1"
"picocolors": "^1.0.1",
"pnpm": "^9.7.1",
"rimraf": "^6.0.1",
"typescript": "^5.5.4",
"unbuild": "^2.0.0",
"vite": "^5.4.1",
"vitest": "^2.0.5"
}
}
9 changes: 4 additions & 5 deletions packages/case-police/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

<!-- @case-police-ignore -->

- Git**H**ub, not *Github*
- Type**S**cript, not *Typescript*
- **m**acOS, not *MacOS*
- **VS C**ode, not *Vscode*
- Git**H**ub, not _Github_
- Type**S**cript, not _Typescript_
- **m**acOS, not _MacOS_
- **VS C**ode, not _Vscode_
- ...

Make the case correct, PLEASE!

## Documentation

[Read full documentation](https://github.com/antfu/case-police#readme).

14 changes: 7 additions & 7 deletions packages/case-police/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "case-police",
"type": "module",
"version": "0.6.1",
"packageManager": "pnpm@8.4.0",
"packageManager": "pnpm@9.7.1",
"description": "Make the case correct, PLEASE!",
"author": "Anthony Fu <[email protected]>",
"license": "MIT",
Expand All @@ -20,13 +20,13 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./cli": {
"types": "./dist/cli.d.ts",
"require": "./dist/cli.cjs",
"import": "./dist/cli.mjs"
"import": "./dist/cli.mjs",
"require": "./dist/cli.cjs"
},
"./*": "./*"
},
Expand All @@ -37,9 +37,9 @@
"case-police": "./bin/case-police.mjs"
},
"files": [
"dist",
"bin",
"dict"
"dict",
"dist"
],
"scripts": {
"build": "rimraf dist && unbuild",
Expand Down
3 changes: 3 additions & 0 deletions packages/case-police/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable no-console */
import { existsSync, promises as fs } from 'node:fs'
import process from 'node:process'
import fg from 'fast-glob'
import c from 'picocolors'
// @ts-expect-error missing types
import parseIgnore from 'parse-gitignore'
import isText from 'is-text-path'
import pLimit from 'p-limit'
Expand Down
3 changes: 2 additions & 1 deletion packages/case-police/src/shim.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Buffer } from 'node:buffer'

declare module 'parse-gitignore' {
interface Section {
Expand All @@ -18,7 +19,7 @@ declare module 'parse-gitignore' {
unique?: boolean
ignore?: string[]
unignore?: string[]
formatSection? (section?: Section): string
formatSection?: (section?: Section) => string
}

declare function parseGitignore(input: string, options?: ParseOptions): ParsedResult
Expand Down
3 changes: 2 additions & 1 deletion packages/case-police/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const DICT_FOLDER = dictDir
export const IGNORE_KEY = '@case-police-ignore'
export const DISABLE_KEY = '@case-police-disable'

export const IGNORE_REGEX = /@case-police-ignore\s+([^\s]+)/g
export const IGNORE_REGEX = /@case-police-ignore\s+(\S+)/g

export const UTF8_RANGE = '[\u0080-\uFFFF]'

Expand Down Expand Up @@ -112,6 +112,7 @@ export async function loadAllPresets() {
}

function containsUTF8(code: string, key: string, index: number) {
// eslint-disable-next-line regexp/no-obscure-range
const utf8Regex = new RegExp(`${UTF8_RANGE}`)
const head = code.charAt(index - 1)
const tail = code.charAt(index + key.length)
Expand Down
9 changes: 6 additions & 3 deletions packages/eslint-plugin-case-police/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
"build": "rimraf dist && unbuild",
"lint": "nr build && cd ./fixture && eslint ./src"
},
"peerDependencies": {
"eslint": "^9.9.0"
},
"dependencies": {
"@typescript-eslint/utils": "^5.59.2",
"@typescript-eslint/utils": "^8.1.0",
"case-police": "workspace:*",
"synckit": "^0.8.5"
"synckit": "^0.9.1"
},
"devDependencies": {
"@typescript-eslint/parser": "^5.59.2",
"@typescript-eslint/parser": "^8.1.0",
"eslint-plugin-case-police": "workspace:*"
}
}
47 changes: 19 additions & 28 deletions packages/eslint-plugin-case-police/src/rule/string-check.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import fs from 'node:fs'
import path from 'node:path'
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import { run } from 'eslint-vitest-rule-tester'
import tsPaser from '@typescript-eslint/parser'
import type { RuleOption } from '../types'
import rule, { RULE_NAME } from './string-check'
import rule from './string-check'

const valids: ([string, [RuleOption]] | [string])[] = [
['const a="Ant Design"'],
['const a="iOc"', [{ presets: ['softwares'] }]],
]

const original = fs.readFileSync(path.join(__dirname, '../test/original.txt'), 'utf-8')
const expect = fs.readFileSync(path.join(__dirname, '../test/expect.txt'), 'utf-8')

const invalids: ([string, string, number, [RuleOption]] | [string, string, number])[] = [
['const a="Typescript \\n Ant design"', 'const a="TypeScript \\n Ant Design"', 2],
['const a="Typescript"', 'const a="TypeScript"', 1],
Expand All @@ -23,19 +20,14 @@ const invalids: ([string, string, number, [RuleOption]] | [string, string, numbe
['const a="alphaGo"', 'const a="AlphaGo"', 1, [{ presets: ['brands'] }]],
]

it('runs', () => {
const ruleTester: RuleTester = new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
})

const invalidArr = [
run({
rule,
invalid: [
{
code: original,
output: expect,
errors: new Array(5).fill({ messageId: 'CasePoliceError' }),
code: fs.readFileSync(path.join(__dirname, '../test/original.txt'), 'utf-8'),
output: fs.readFileSync(path.join(__dirname, '../test/expect.txt'), 'utf-8'),
},
].concat(
invalids.map(i => i[3]
...invalids.map(i => i[3]
? ({
code: i[0],
output: i[1],
Expand All @@ -47,15 +39,14 @@ it('runs', () => {
output: i[1],
errors: Array.from({ length: i[2] }, _ => ({ messageId: 'CasePoliceError' })),
})),
)

ruleTester.run(RULE_NAME, rule, {
valid: valids.map(i => i[1]
? ({
code: i[0],
options: i?.[1],
})
: ({ code: i[0] })),
invalid: invalidArr,
})
],
valid: valids.map(i => i[1]
? ({
code: i[0],
options: i?.[1],
})
: ({ code: i[0] })),
languageOptions: {
parser: tsPaser,
},
})
Loading

0 comments on commit cc3e1b1

Please sign in to comment.