Skip to content

Commit

Permalink
fix lint autofix (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnecec authored Dec 15, 2023
1 parent 1417a3d commit d49e4b4
Show file tree
Hide file tree
Showing 24 changed files with 419 additions and 583 deletions.
6 changes: 6 additions & 0 deletions .changeset/chatty-stingrays-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"prettier-plugin-zh": patch
"core": patch
---

lint autofix
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@nnecec/prettier-config"
1 change: 1 addition & 0 deletions apps/website/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/default
import nextra from 'nextra'

const withNextra = nextra({
Expand Down
12 changes: 6 additions & 6 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@types/react": "^18.2.39",
"@next/eslint-plugin-next": "~13.4.7",
"@types/node": "^20.10.4",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.17",
"autoprefixer": "^10.4.16",
"@next/eslint-plugin-next": "~13.4.7",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"typescript": "^5.3.2"
"postcss": "^8.4.32",
"tailwindcss": "^3.3.6",
"typescript": "^5.3.3"
}
}
4 changes: 2 additions & 2 deletions apps/website/theme.config.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { DocsThemeConfig } from 'nextra-theme-docs'

import { useRouter } from 'next/router'
import { useConfig } from 'nextra-theme-docs'

import type { DocsThemeConfig } from 'nextra-theme-docs'

import { Logo } from './components/logo'

const config: DocsThemeConfig = {
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "zh",
"private": true,
"type": "module",
"scripts": {
"build": "turbo run build",
"changeset": "changeset",
Expand All @@ -11,17 +12,18 @@
"version": "changeset version"
},
"dependencies": {
"@changesets/cli": "^2.26.2"
"@changesets/cli": "^2.27.1"
},
"devDependencies": {
"@nnecec/eslint-config": "^0.7.5",
"@nnecec/prettier-config": "^0.3.2",
"@turbo/gen": "^1.10.16",
"@next/eslint-plugin-next": "~13.4.7",
"eslint": "^8.54.0",
"prettier": "^3.1.0",
"@nnecec/eslint-config": "^0.8.6",
"@nnecec/prettier-config": "^0.3.3",
"@nnecec/tsconfig": "^0.2.2",
"@turbo/gen": "^1.11.2",
"eslint": "^8.55.0",
"prettier": "^3.1.1",
"prettier-plugin-zh": "workspace:*",
"turbo": "^1.10.16"
"turbo": "^1.11.2"
},
"packageManager": "[email protected]"
}
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "core",
"version": "0.1.0",
"private": true,
"description": "ESLint plugin for formatting Zh(Chinese) text.",
"description": "Formatting Chinese text.",
"keywords": [
"eslint",
"eslint-plugin",
Expand All @@ -25,12 +25,12 @@
],
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
"test": "echo \"Error: no test specified\" && exit 0"
},
"devDependencies": {
"@nnecec/tsconfig": "^0.2.1",
"@nnecec/tsconfig": "^0.2.2",
"tsup": "^8.0.1"
},
"publishConfig": {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/rules/no-space-between-number-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export function noSpaceBetweenNumberUnit(text: string, units?: string[]) {
if (!units || units.length === 0) return text

return text.replaceAll(new RegExp(`\\d+\\s+(${units.join('|')})`, 'g'), match => {
console.log(match)
return match.replaceAll(' ', '')
})
}
1 change: 1 addition & 0 deletions packages/core/src/rules/strict-fullwidth-and-halfwidth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// eslint-disable-next-line unicorn/no-empty-file
8 changes: 4 additions & 4 deletions packages/eslint-plugin-zh/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
extends: ["next", "turbo", "prettier"],
extends: ['next', 'turbo', 'prettier'],
parserOptions: {
babelOptions: {
presets: [require.resolve("next/babel")],
presets: [require.resolve('next/babel')],
},
},
rules: {
"@next/next/no-html-link-for-pages": "off",
'@next/next/no-html-link-for-pages': 'off',
},
};
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-zh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test": "echo \"Error: no test specified\" && exit 0"
},
"devDependencies": {
"eslint": "^8.54.0"
"eslint": "^8.55.0"
},
"peerDependencies": {
"eslint": ">=8.0.0"
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin-zh/rules/space-around-alphabet.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const spaceAroundAlphabet = () => {}
7 changes: 4 additions & 3 deletions packages/prettier-plugin-zh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
],
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
"test": "echo \"Error: no test specified\" && exit 0"
},
"dependencies": {
"prettier": "^3.1.1"
},
"devDependencies": {
"@nnecec/tsconfig": "^0.2.1",
"core": "workspace:*",
"prettier": "^3.1.0",
"tsup": "^8.0.1"
},
"peerDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/prettier-plugin-zh/src/parsers/base-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { parsers as markdownParsers } from 'prettier/plugins/markdown'


export function getBasePlugins() {
return {
parsers: {
Expand Down
7 changes: 3 additions & 4 deletions packages/prettier-plugin-zh/src/parsers/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { Parser, Plugin } from 'prettier'

import { defaultTransform, transformMarkdown } from '../transforms'

import { getBasePlugins } from './base-parser'

import type { Transform } from '../transforms/types'
import type { ParserFormat } from './base-parser'

import { defaultTransform, transformMarkdown } from '../transforms'
import { getBasePlugins } from './base-parser'

const base = getBasePlugins()

export function createParser(parserFormat: ParserFormat, transform: Transform = defaultTransform): Parser {
Expand Down
12 changes: 6 additions & 6 deletions packages/prettier-plugin-zh/src/transforms/transform-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
spaceAroundNumber,
} from 'core'

import { traverseChildren } from '../utils'

import type { MarkdownAST } from '../types'
import type { Transform } from './types'

import { traverseChildren } from '../utils'

export const transformMarkdown: Transform<MarkdownAST> = (ast, options) => {
traverseChildren<MarkdownAST>(ast, ({ child, nextSibling, prevSibling }) => {
switch (child.type) {
Expand All @@ -35,16 +35,16 @@ export const transformMarkdown: Transform<MarkdownAST> = (ast, options) => {
case 'inlineCode': {
if (options.spaceAroundCode) {
const [prevSiblingValue, nextSiblingValue] = spaceAroundCode(prevSibling?.value, nextSibling?.value)
if (prevSibling) prevSibling.value = prevSiblingValue!
if (nextSibling) nextSibling.value = nextSiblingValue!
if (prevSibling && prevSiblingValue) prevSibling.value = prevSiblingValue
if (nextSibling && nextSiblingValue) nextSibling.value = nextSiblingValue
}
break
}
case 'link': {
if (options.spaceAroundLink) {
const [prevSiblingValue, nextSiblingValue] = spaceAroundLink(prevSibling?.value, nextSibling?.value)
if (prevSibling) prevSibling.value = prevSiblingValue!
if (nextSibling) nextSibling.value = nextSiblingValue!
if (prevSibling && prevSiblingValue) prevSibling.value = prevSiblingValue
if (nextSibling && nextSiblingValue) nextSibling.value = nextSiblingValue
}
break
}
Expand Down
1 change: 0 additions & 1 deletion packages/prettier-plugin-zh/src/transforms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import type { ParserOptions } from 'prettier'

import type { AST, ZhOptions } from '../types'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Transform<T extends AST = any> = (ast: T, options: ParserOptions & ZhOptions) => void
1 change: 0 additions & 1 deletion packages/prettier-plugin-zh/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type TraverseContext<T> = {
}

type WithChildren = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
children?: any[]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { defaultUnits } = require('../..')
const { defaultUnits } = require('../../dist')
/**
* @type {import('prettier').Config&import('../..').ZhOptions}
* @type {import('prettier').Config&import('../../dist').ZhOptions}
*/
module.exports = {
...require('@nnecec/prettier-config'),
noDuplicatePunctuation: true,
noSpaceBetweenNumberUnit: defaultUnits,
plugins: ['prettier-plugin-zh'],
spaceAroundLink: true,
spaceAroundCode: true,
spaceAroundLink: true,
}
5 changes: 1 addition & 4 deletions packages/prettier-plugin-zh/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": ["@nnecec/tsconfig"],
"compilerOptions": {
"noImplicitAny": false
}
"extends": "../../tsconfig.json"
}
Loading

0 comments on commit d49e4b4

Please sign in to comment.