feat: custom plugin
This commit is contained in:
parent
f1644757c8
commit
ded3cf2da2
@ -6,12 +6,14 @@
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"prepare":"pnpm -r run stub",
|
||||
"release": "bumpp package.json packages/*/package.json --commit --push --tag && pnpm -r publish --access public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "*",
|
||||
"bumpp": "^7.1.1",
|
||||
"eslint": "^8.12.0",
|
||||
"eslint-plugin-antfu": "workspace:*",
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
"eslint": ">=7.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@antfu/eslint-config-react": "^0.19.1",
|
||||
"@antfu/eslint-config-vue": "^0.19.1",
|
||||
"@antfu/eslint-config-react": "workspace:*",
|
||||
"@antfu/eslint-config-vue": "workspace:*",
|
||||
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
||||
"@typescript-eslint/parser": "^5.17.0",
|
||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||
|
@ -32,6 +32,7 @@ module.exports = {
|
||||
plugins: [
|
||||
'html',
|
||||
'unicorn',
|
||||
'antfu',
|
||||
],
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
@ -288,5 +289,8 @@ module.exports = {
|
||||
// yml
|
||||
'yml/quotes': ['error', { prefer: 'single', avoidEscape: false }],
|
||||
'yml/no-empty-document': 'off',
|
||||
|
||||
// antfu
|
||||
'antfu/no-leading-newline': 'error',
|
||||
},
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
"eslint": ">=7.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint-plugin-antfu": "workspace:*",
|
||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||
"eslint-plugin-html": "^6.2.0",
|
||||
"eslint-plugin-import": "^2.25.4",
|
||||
|
9
packages/eslint-plugin-antfu/.eslintrc.json
Normal file
9
packages/eslint-plugin-antfu/.eslintrc.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "@antfu",
|
||||
"plugins": [
|
||||
"antfu"
|
||||
],
|
||||
"rules": {
|
||||
"antfu/no-leading-newline": "error"
|
||||
}
|
||||
}
|
12
packages/eslint-plugin-antfu/build.config.ts
Normal file
12
packages/eslint-plugin-antfu/build.config.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { defineBuildConfig } from 'unbuild'
|
||||
|
||||
export default defineBuildConfig({
|
||||
entries: [
|
||||
'src/index',
|
||||
],
|
||||
declaration: true,
|
||||
clean: true,
|
||||
rollup: {
|
||||
emitCJS: true,
|
||||
},
|
||||
})
|
29
packages/eslint-plugin-antfu/package.json
Normal file
29
packages/eslint-plugin-antfu/package.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "eslint-plugin-antfu",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf dist && unbuild",
|
||||
"stub": "unbuild --stub",
|
||||
"prepublishOnly": "nr build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@typescript-eslint/utils": "^5.17.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"unbuild": "^0.7.0"
|
||||
}
|
||||
}
|
7
packages/eslint-plugin-antfu/src/index.ts
Normal file
7
packages/eslint-plugin-antfu/src/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import noLeadingNewline from './rules/no-leading-newline'
|
||||
|
||||
export default {
|
||||
rules: {
|
||||
'no-leading-newline': noLeadingNewline,
|
||||
},
|
||||
}
|
44
packages/eslint-plugin-antfu/src/rules/no-leading-newline.ts
Normal file
44
packages/eslint-plugin-antfu/src/rules/no-leading-newline.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { createEslintRule } from '../utils'
|
||||
|
||||
export const RULE_NAME = 'no-leading-newline'
|
||||
export type MessageIds = 'noLeadingNewline'
|
||||
export type Options = []
|
||||
|
||||
export default createEslintRule<Options, MessageIds>({
|
||||
name: RULE_NAME,
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Do not allow leading newline',
|
||||
recommended: 'error',
|
||||
},
|
||||
fixable: 'whitespace',
|
||||
schema: [],
|
||||
messages: {
|
||||
noLeadingNewline: 'No leading newline allowed',
|
||||
},
|
||||
},
|
||||
defaultOptions: [],
|
||||
create: (context) => {
|
||||
return {
|
||||
Program(node) {
|
||||
const code = context.getSourceCode()
|
||||
const match = code.text.match(/^[\s]+/)?.[0] || ''
|
||||
if (match.includes('\n')) {
|
||||
const line = match.split('\n')
|
||||
context.report({
|
||||
node,
|
||||
loc: {
|
||||
start: { line: 0, column: 0 },
|
||||
end: { line: line.length - 1, column: line[line.length - 1].length },
|
||||
},
|
||||
messageId: 'noLeadingNewline',
|
||||
fix(fixer) {
|
||||
return fixer.replaceTextRange([0, match.length], '')
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
5
packages/eslint-plugin-antfu/src/utils.ts
Normal file
5
packages/eslint-plugin-antfu/src/utils.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { ESLintUtils } from '@typescript-eslint/utils'
|
||||
|
||||
export const createEslintRule = ESLintUtils.RuleCreator(
|
||||
ruleName => ruleName,
|
||||
)
|
@ -19,7 +19,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"@antfu/eslint-config-ts": "^0.19.1",
|
||||
"@antfu/eslint-config-ts": "workspace:*",
|
||||
"eslint-plugin-react": "^7.29.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -17,7 +17,7 @@
|
||||
"typescript": ">=3.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"@antfu/eslint-config-basic": "^0.19.1",
|
||||
"@antfu/eslint-config-basic": "workspace:*",
|
||||
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
||||
"@typescript-eslint/parser": "^5.17.0"
|
||||
},
|
||||
|
@ -16,7 +16,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"@antfu/eslint-config-ts": "^0.19.1",
|
||||
"@antfu/eslint-config-ts": "workspace:*",
|
||||
"eslint-plugin-vue": "^8.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
1088
pnpm-lock.yaml
1088
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user