Skip to content

Commit 42dd2c2

Browse files
authored
chore: introduce eslint flat config (#1758)
1 parent 07049cc commit 42dd2c2

File tree

17 files changed

+192
-85
lines changed

17 files changed

+192
-85
lines changed

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 0 additions & 42 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"editor.formatOnPaste": true,
99
"editor.formatOnType": true,
1010
"editor.codeActionsOnSave": {
11-
"source.fixAll.eslint": true
11+
"source.fixAll.eslint": "explicit"
1212
},
13+
"eslint.experimental.useFlatConfig": true,
1314
"typescript.tsdk": "node_modules/typescript/lib",
1415
"volar.tsPlugin": true
1516
}

benchmark/compile.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async function main() {
1313
baseCompile(`hello world`)
1414
})
1515
.add(`compile complex message`, () => {
16+
// eslint-disable-next-line no-irregular-whitespace
1617
baseCompile(`@.caml:{'no apples'} 0 | {0} apple 0 | {n} apples 0`)
1718
})
1819
.on('error', event => {

eslint.config.mjs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import globals from 'globals'
2+
import js from '@eslint/js'
3+
import { FlatCompat } from '@eslint/eslintrc'
4+
import ts from 'typescript-eslint'
5+
import eslintConfigPrettier from 'eslint-config-prettier'
6+
7+
const vue = extendVuePlugin('plugin:vue/vue3-recommended', ts.parser)
8+
9+
/** @type { import("eslint").Linter.FlatConfig[] } */
10+
export default [
11+
// ignore globally
12+
{
13+
ignores: [
14+
'**/dist/**',
15+
'**/fixtures/**',
16+
'**/coverage/**',
17+
'**/.vitepress/**',
18+
'**/.vuepress/**',
19+
'**/test/**',
20+
'**/examples/**',
21+
'shim.d.ts',
22+
'.eslintcache',
23+
'.eslintrc.cjs'
24+
]
25+
},
26+
27+
js.configs.recommended,
28+
...ts.configs.recommended,
29+
eslintConfigPrettier,
30+
...vue,
31+
32+
// globals
33+
{
34+
// files: ['**/*.js', '**/*.ts', '**/*.vue', '**/*.json'],
35+
languageOptions: {
36+
globals: {
37+
__DEV__: true,
38+
__COMMIT__: true,
39+
page: true,
40+
browser: true,
41+
context: true,
42+
...globals.node
43+
},
44+
parserOptions: { sourceType: 'module' }
45+
}
46+
},
47+
48+
// custom rules
49+
{
50+
rules: {
51+
'object-curly-spacing': 'off',
52+
'@typescript-eslint/ban-types': 'off',
53+
'@typescript-eslint/ban-ts-ignore': 'off',
54+
'@typescript-eslint/ban-ts-comment': 'off',
55+
'@typescript-eslint/explicit-function-return-type': 'off',
56+
'@typescript-eslint/member-delimiter-style': 'off',
57+
'@typescript-eslint/no-use-before-define': 'off',
58+
'@typescript-eslint/no-var-requires': 'off',
59+
'@typescript-eslint/no-non-null-assertion': 'off',
60+
'vue/one-component-per-file': 'off',
61+
'vue/multi-word-component-names': 'off',
62+
'vue/experimental-script-setup-vars': 'off',
63+
'vue/no-deprecated-props-default-this': 'off'
64+
}
65+
}
66+
]
67+
68+
/**
69+
* extend eslint-plugin-vue with @typescript-eslint/parser
70+
* (NOTE: eslint-plugin-vue flat config WIP currently https://github.com/vuejs/eslint-plugin-vue/issues/1291)
71+
*
72+
* @param { 'plugin:vue/vue3-essential' | 'plugin:vue/vue3-strongly-recommended' | 'plugin:vue/vue3-recommended' } vueConfigPattern
73+
* @param { import("typescript-eslint").Config.parser } tsParser
74+
*
75+
* @return { import("eslint").Linter.FlatConfig[] }
76+
*/
77+
function extendVuePlugin(vueConfigPattern, tsParser) {
78+
const compat = new FlatCompat()
79+
const vuePlugin = compat.extends(vueConfigPattern)
80+
const vueLangOptions = vuePlugin[2]
81+
vueLangOptions.files = [
82+
'**/*.vue',
83+
'**/*.ts',
84+
'**/*.tsx',
85+
'**/*.mts',
86+
'**/*.cts'
87+
]
88+
vueLangOptions.languageOptions = {
89+
// NOTE:
90+
// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
91+
parserOptions: {
92+
parser: tsParser
93+
},
94+
ecmaVersion: 'latest'
95+
}
96+
return vuePlugin
97+
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"format:package": "node -r esbuild-register ./scripts/fixpack.ts",
5151
"format:prettier": "prettier --config prettier.config.mjs --ignore-path .prettierignore --list-different '**/*.{ts,js,json,html}'",
5252
"lint": "run-p lint:secret lint:codes lint:docs",
53-
"lint:codes": "eslint --cache ./packages ./test-dts ./e2e ./benchmark --ext .js,.mjs,.ts,.vue",
53+
"lint:codes": "eslint . --cache",
5454
"lint:docs": "textlint --config .textlintrc.js docs/*.md docs/advanced/**/*.md docs/essentials/**/*.md docs/migration/**/*.md docs/api/injection.md packages/**/*.md",
5555
"lint:fix": "run-p \"lint:codes --fix\" \"lint:docs --fix\"",
5656
"lint:secret": "npx secretlint \"**/*\"",
@@ -69,6 +69,8 @@
6969
"test:unit": "cross-env TZ=UTC vitest run -c ./vitest.unit.config.ts"
7070
},
7171
"devDependencies": {
72+
"@eslint/eslintrc": "^2.1.4",
73+
"@eslint/js": "^8.57.0",
7274
"@intlify/core-base": "workspace:*",
7375
"@intlify/message-compiler": "workspace:*",
7476
"@microsoft/api-extractor": "7.15.2",
@@ -96,6 +98,7 @@
9698
"eslint-plugin-vue": "^9.22.0",
9799
"execa": "^5.0.0",
98100
"fixpack": "^4.0.0",
101+
"globals": "^14.0.0",
99102
"globby": "^14.0.1",
100103
"jiti": "^1.21.0",
101104
"js-yaml": "^4.1.0",
@@ -158,11 +161,11 @@
158161
],
159162
"*.{js,vue}": [
160163
"prettier --write",
161-
"eslint --fix --ext .js,.vue"
164+
"eslint --fix"
162165
],
163166
"*.ts?(x)": [
164167
"prettier --parser=typescript --write",
165-
"eslint --fix --ext .ts"
168+
"eslint --fix"
166169
],
167170
"*": [
168171
"secretlint"

packages/core-base/src/format.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,39 @@ function formatMessagePart<Message = string>(
7575
): MessageType<Message> {
7676
const type = node.t || node.type
7777
switch (type) {
78-
case NodeTypes.Text:
78+
case NodeTypes.Text: {
7979
const text = node as TextNode
8080
return (text.v || text.value) as MessageType<Message>
81-
case NodeTypes.Literal:
81+
}
82+
case NodeTypes.Literal: {
8283
const literal = node as LiteralNode
8384
return (literal.v || literal.value) as MessageType<Message>
84-
case NodeTypes.Named:
85+
}
86+
case NodeTypes.Named: {
8587
const named = node as NamedNode
8688
return ctx.interpolate(ctx.named(named.k || named.key))
87-
case NodeTypes.List:
89+
}
90+
case NodeTypes.List: {
8891
const list = node as ListNode
8992
return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index))
90-
case NodeTypes.Linked:
93+
}
94+
case NodeTypes.Linked: {
9195
const linked = node as LinkedNode
9296
const modifier = linked.m || linked.modifier
9397
return ctx.linked(
9498
formatMessagePart(ctx, linked.k || linked.key) as string,
9599
modifier ? (formatMessagePart(ctx, modifier) as string) : undefined,
96100
ctx.type
97101
)
98-
case NodeTypes.LinkedKey:
102+
}
103+
case NodeTypes.LinkedKey: {
99104
const linkedKey = node as LinkedKeyNode
100105
return (linkedKey.v || linkedKey.value) as MessageType<Message>
101-
case NodeTypes.LinkedModifier:
106+
}
107+
case NodeTypes.LinkedModifier: {
102108
const linkedModifier = node as LinkedModifierNode
103109
return (linkedModifier.v || linkedModifier.value) as MessageType<Message>
110+
}
104111
default:
105112
throw new Error(`unhandled node type on format message part: ${type}`)
106113
}

packages/format-explorer/src/App.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ const onChangeOptions = async (options: CompileOptions) => {
222222
@change-model="onChangeModel"
223223
@ready="onReadyInput"
224224
/>
225-
<Editor class="output" :code="genCodes" @ready="onReadyOutput" />
225+
<Editor
226+
class="output"
227+
:code="genCodes"
228+
@ready="onReadyOutput"
229+
/>
226230
</div>
227231
</div>
228232
</template>

packages/format-explorer/src/components/Navigation.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ const commitHistoryURL = 'https://app.netlify.com/sites/format-explorer/deploys'
77
<template>
88
<div>
99
<h1>Intlify Message Format Explorer</h1>
10-
<a :href="commitURL" target="_blank">{{ commitLabel }}</a>
10+
<a
11+
:href="commitURL"
12+
target="_blank"
13+
>{{ commitLabel }}</a>
1114
|
12-
<a :href="commitHistoryURL" target="_blank">History</a>
15+
<a
16+
:href="commitHistoryURL"
17+
target="_blank"
18+
>History</a>
1319
</div>
1420
</template>
1521

packages/format-explorer/src/components/Options.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ watch(compilerOptions, val => {
4747
name="mode"
4848
:checked="compilerOptions.mode === 'normal'"
4949
@change="compilerOptions.mode = 'normal'"
50-
/>
50+
>
5151
<label for="mode-normal">normal</label>
5252
<input
5353
id="mode-arrow"
5454
type="radio"
5555
name="mode"
5656
:checked="compilerOptions.mode === 'arrow'"
5757
@change="compilerOptions.mode = 'arrow'"
58-
/>
58+
>
5959
<label for="mode-arrow">arrow</label>
6060
</li>
6161
<li>
@@ -69,7 +69,7 @@ watch(compilerOptions, val => {
6969
$event.target as HTMLInputElement
7070
).checked
7171
"
72-
/>
72+
>
7373
<label for="location">location</label>
7474
</li>
7575
<li>
@@ -83,7 +83,7 @@ watch(compilerOptions, val => {
8383
$event.target as HTMLInputElement
8484
).checked
8585
"
86-
/>
86+
>
8787
<label for="indent">needIndent</label>
8888
</li>
8989
<li>
@@ -97,7 +97,7 @@ watch(compilerOptions, val => {
9797
$event.target as HTMLInputElement
9898
).checked
9999
"
100-
/>
100+
>
101101
<label for="sourcemap">sourceMap</label>
102102
</li>
103103
<li>
@@ -109,7 +109,7 @@ watch(compilerOptions, val => {
109109
@change="
110110
compilerOptions.jit = ($event.target as HTMLInputElement).checked
111111
"
112-
/>
112+
>
113113
<label for="jit">jit</label>
114114
</li>
115115
<li>
@@ -123,7 +123,7 @@ watch(compilerOptions, val => {
123123
$event.target as HTMLInputElement
124124
).checked
125125
"
126-
/>
126+
>
127127
<label for="optimize">optimize</label>
128128
</li>
129129
</ul>

0 commit comments

Comments
 (0)