Skip to content

Commit 8eab7db

Browse files
committed
update eslint env
1 parent 251f8d7 commit 8eab7db

File tree

5 files changed

+99
-37
lines changed

5 files changed

+99
-37
lines changed

.eslintrc.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ module.exports = {
66
node: true,
77
jest: true
88
},
9-
extends: ['plugin:vue-libs/recommended'],
9+
extends: [
10+
'plugin:vue-libs/recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
'plugin:@typescript-eslint/eslint-recommended',
13+
'prettier/@typescript-eslint',
14+
'plugin:prettier/recommended'
15+
],
1016
plugins: ['@typescript-eslint'],
1117
parser: 'vue-eslint-parser',
1218
parserOptions: {
1319
parser: '@typescript-eslint/parser',
1420
sourceType: 'module'
1521
},
1622
rules: {
17-
'no-unused-vars': 'off', // HACK: due to override with @typescript-eslint/no-unused-vars
18-
'@typescript-eslint/no-unused-vars': [2, { vars: 'all', args: 'none' }]
23+
'object-curly-spacing': 'off',
24+
'@typescript-eslint/explicit-function-return-type': 'off',
25+
'@typescript-eslint/member-delimiter-style': 'off',
26+
'@typescript-eslint/no-use-before-define': 'off'
1927
}
2028
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
"@types/node": "^13.1.4",
3737
"@types/webpack": "^4.41.1",
3838
"@types/webpack-merge": "^4.1.5",
39-
"@typescript-eslint/eslint-plugin": "^2.14.0",
40-
"@typescript-eslint/parser": "^2.14.0",
41-
"@typescript-eslint/typescript-estree": "^2.14.0",
39+
"@typescript-eslint/eslint-plugin": "^2.26.0",
40+
"@typescript-eslint/parser": "^2.26.0",
41+
"@typescript-eslint/typescript-estree": "^2.26.0",
4242
"eslint": "^6.8.0",
43+
"eslint-config-prettier": "^6.10.1",
44+
"eslint-plugin-prettier": "^3.1.2",
4345
"eslint-plugin-vue-libs": "^4.0.0",
4446
"jest": "^25.2.4",
4547
"jest-watch-typeahead": "^0.5.0",
@@ -82,6 +84,7 @@
8284
"clean": "rm -rf ./coverage && rm -rf ./lib/*.js*",
8385
"coverage": "opener coverage/lcov-report/index.html",
8486
"lint": "eslint ./src ./test --ext .ts",
87+
"lint:fix": "yarn lint --fix",
8588
"release:prepare": "shipjs prepare",
8689
"release:trigger": "shipjs trigger",
8790
"format": "prettier --config .prettierrc --ignore-path .prettierignore '**/*.{js,json,html}'",

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import JSON5 from 'json5'
55
import yaml from 'js-yaml'
66

77
const loader: webpack.loader.Loader = function (
8-
source: string | Buffer, sourceMap: RawSourceMap | undefined): void {
8+
source: string | Buffer,
9+
sourceMap: RawSourceMap | undefined
10+
): void {
911
if (this.version && Number(this.version) >= 2) {
1012
try {
1113
this.cacheable && this.cacheable()
12-
this.callback(null, `module.exports = ${generateCode(source, parse(this.resourceQuery))}`, sourceMap)
14+
this.callback(
15+
null,
16+
`module.exports = ${generateCode(source, parse(this.resourceQuery))}`,
17+
sourceMap
18+
)
1319
} catch (err) {
1420
this.emitError(err.message)
1521
this.callback(err)
@@ -21,7 +27,7 @@ const loader: webpack.loader.Loader = function (
2127
}
2228
}
2329

24-
function generateCode (source: string | Buffer, query: ParsedUrlQuery): string {
30+
function generateCode(source: string | Buffer, query: ParsedUrlQuery): string {
2531
const data = convert(source, query.lang as string)
2632
let value = JSON.parse(data)
2733

@@ -43,7 +49,7 @@ function generateCode (source: string | Buffer, query: ParsedUrlQuery): string {
4349
return code
4450
}
4551

46-
function convert (source: string | Buffer, lang: string): string {
52+
function convert(source: string | Buffer, lang: string): string {
4753
const value = Buffer.isBuffer(source) ? source.toString() : source
4854

4955
switch (lang) {

test/utils.ts

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { JSDOM, VirtualConsole, DOMWindow } from 'jsdom'
66
import { VueLoaderPlugin } from 'vue-loader'
77

88
type BundleResolve = {
9-
code: string,
9+
code: string
1010
stats: webpack.Stats
1111
}
1212

1313
type BundleResolveResolve = BundleResolve & {
14-
jsdomError: any,
15-
instance: any,
16-
window: DOMWindow,
17-
module: any,
18-
exports: any
14+
jsdomError: any // eslint-disable-line @typescript-eslint/no-explicit-any
15+
instance: any // eslint-disable-line @typescript-eslint/no-explicit-any
16+
window: DOMWindow
17+
module: any // eslint-disable-line @typescript-eslint/no-explicit-any
18+
exports: any // eslint-disable-line @typescript-eslint/no-explicit-any
1919
}
2020

21-
export function bundle (fixture: string, options = {}): Promise<BundleResolve> {
21+
export function bundle(fixture: string, options = {}): Promise<BundleResolve> {
2222
const baseConfig: webpack.Configuration = {
2323
mode: 'development',
2424
devtool: false,
@@ -33,20 +33,19 @@ export function bundle (fixture: string, options = {}): Promise<BundleResolve> {
3333
filename: 'bundle.js'
3434
},
3535
module: {
36-
rules: [{
37-
test: /\.vue$/,
38-
loader: 'vue-loader'
39-
}, {
40-
resourceQuery: /blockType=i18n/,
41-
type: 'javascript/auto',
42-
use: [
43-
path.resolve(__dirname, '../src/index.ts')
44-
]
45-
}]
36+
rules: [
37+
{
38+
test: /\.vue$/,
39+
loader: 'vue-loader'
40+
},
41+
{
42+
resourceQuery: /blockType=i18n/,
43+
type: 'javascript/auto',
44+
use: [path.resolve(__dirname, '../src/index.ts')]
45+
}
46+
]
4647
},
47-
plugins: [
48-
new VueLoaderPlugin()
49-
]
48+
plugins: [new VueLoaderPlugin()]
5049
}
5150

5251
const config = merge({}, baseConfig, options)
@@ -57,14 +56,21 @@ export function bundle (fixture: string, options = {}): Promise<BundleResolve> {
5756

5857
return new Promise((resolve, reject) => {
5958
compiler.run((err, stats) => {
60-
if (err) { return reject(err) }
61-
if (stats.hasErrors()) { return reject(new Error(stats.toJson().errors.join(' | '))) }
59+
if (err) {
60+
return reject(err)
61+
}
62+
if (stats.hasErrors()) {
63+
return reject(new Error(stats.toJson().errors.join(' | ')))
64+
}
6265
resolve({ code: mfs.readFileSync('/bundle.js').toString(), stats })
6366
})
6467
})
6568
}
6669

67-
export async function bundleAndRun (fixture: string, config = {}): Promise<BundleResolveResolve> {
70+
export async function bundleAndRun(
71+
fixture: string,
72+
config = {}
73+
): Promise<BundleResolveResolve> {
6874
const { code, stats } = await bundle(fixture, config)
6975

7076
let dom: JSDOM | null = null
@@ -91,5 +97,13 @@ export async function bundleAndRun (fixture: string, config = {}): Promise<Bundl
9197
module.beforeCreate.forEach((hook: Function) => hook.call(instance))
9298
}
9399

94-
return Promise.resolve({ window, module, exports, instance, code, jsdomError, stats })
100+
return Promise.resolve({
101+
window,
102+
module,
103+
exports,
104+
instance,
105+
code,
106+
jsdomError,
107+
stats
108+
})
95109
}

yarn.lock

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@
739739
dependencies:
740740
"@types/yargs-parser" "*"
741741

742-
"@typescript-eslint/eslint-plugin@^2.14.0":
742+
"@typescript-eslint/eslint-plugin@^2.26.0":
743743
version "2.27.0"
744744
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.27.0.tgz#e479cdc4c9cf46f96b4c287755733311b0d0ba4b"
745745
integrity sha512-/my+vVHRN7zYgcp0n4z5A6HAK7bvKGBiswaM5zIlOQczsxj/aiD7RcgD+dvVFuwFaGh5+kM7XA6Q6PN0bvb1tw==
@@ -759,7 +759,7 @@
759759
eslint-scope "^5.0.0"
760760
eslint-utils "^2.0.0"
761761

762-
"@typescript-eslint/parser@^2.14.0":
762+
"@typescript-eslint/parser@^2.26.0":
763763
version "2.27.0"
764764
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.27.0.tgz#d91664335b2c46584294e42eb4ff35838c427287"
765765
integrity sha512-HFUXZY+EdwrJXZo31DW4IS1ujQW3krzlRjBrFRrJcMDh0zCu107/nRfhk/uBasO8m0NVDbBF5WZKcIUMRO7vPg==
@@ -769,7 +769,7 @@
769769
"@typescript-eslint/typescript-estree" "2.27.0"
770770
eslint-visitor-keys "^1.1.0"
771771

772-
"@typescript-eslint/typescript-estree@2.27.0", "@typescript-eslint/typescript-estree@^2.14.0":
772+
"@typescript-eslint/typescript-estree@2.27.0", "@typescript-eslint/typescript-estree@^2.26.0":
773773
version "2.27.0"
774774
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.27.0.tgz#a288e54605412da8b81f1660b56c8b2e42966ce8"
775775
integrity sha512-t2miCCJIb/FU8yArjAvxllxbTiyNqaXJag7UOpB5DVoM3+xnjeOngtqlJkLRnMtzaRcJhe3CIR9RmL40omubhg==
@@ -2498,6 +2498,20 @@ escodegen@^1.11.1, escodegen@^1.14.1:
24982498
optionalDependencies:
24992499
source-map "~0.6.1"
25002500

2501+
eslint-config-prettier@^6.10.1:
2502+
version "6.10.1"
2503+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.10.1.tgz#129ef9ec575d5ddc0e269667bf09defcd898642a"
2504+
integrity sha512-svTy6zh1ecQojvpbJSgH3aei/Rt7C6i090l5f2WQ4aB05lYHeZIR1qL4wZyyILTbtmnbHP5Yn8MrsOJMGa8RkQ==
2505+
dependencies:
2506+
get-stdin "^6.0.0"
2507+
2508+
eslint-plugin-prettier@^3.1.2:
2509+
version "3.1.2"
2510+
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz#432e5a667666ab84ce72f945c72f77d996a5c9ba"
2511+
integrity sha512-GlolCC9y3XZfv3RQfwGew7NnuFDKsfI4lbvRK+PIIo23SFH+LemGs4cKwzAaRa+Mdb+lQO/STaIayno8T5sJJA==
2512+
dependencies:
2513+
prettier-linter-helpers "^1.0.0"
2514+
25012515
eslint-plugin-vue-libs@^4.0.0:
25022516
version "4.0.0"
25032517
resolved "https://registry.yarnpkg.com/eslint-plugin-vue-libs/-/eslint-plugin-vue-libs-4.0.0.tgz#b1ab44528aa59ce6c2e9fe2fc37cb92e85c2011c"
@@ -2783,6 +2797,11 @@ fast-deep-equal@^3.1.1:
27832797
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
27842798
integrity sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==
27852799

2800+
fast-diff@^1.1.2:
2801+
version "1.2.0"
2802+
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
2803+
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
2804+
27862805
fast-glob@^3.0.3:
27872806
version "3.2.2"
27882807
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.2.tgz#ade1a9d91148965d4bf7c51f72e1ca662d32e63d"
@@ -3028,6 +3047,11 @@ get-stdin@^4.0.1:
30283047
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
30293048
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=
30303049

3050+
get-stdin@^6.0.0:
3051+
version "6.0.0"
3052+
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
3053+
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
3054+
30313055
get-stream@^4.0.0:
30323056
version "4.1.0"
30333057
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
@@ -5439,6 +5463,13 @@ prelude-ls@~1.1.2:
54395463
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
54405464
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
54415465

5466+
prettier-linter-helpers@^1.0.0:
5467+
version "1.0.0"
5468+
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
5469+
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
5470+
dependencies:
5471+
fast-diff "^1.1.2"
5472+
54425473
prettier@^1.18.2:
54435474
version "1.19.1"
54445475
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"

0 commit comments

Comments
 (0)