Skip to content

Commit e28168e

Browse files
committed
chore: update lint & ts
1 parent 51874d9 commit e28168e

File tree

7 files changed

+33
-32
lines changed

7 files changed

+33
-32
lines changed

.eslintrc.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,10 @@ module.exports = {
8888
2,
8989
{
9090
singleline: 20,
91-
multiline: {
92-
max: 1,
93-
allowFirstLine: false,
94-
},
91+
multiline: 1,
9592
},
9693
],
94+
'vue/multi-word-component-names': 'off',
9795
},
9896
globals: {
9997
h: true,

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@
102102
"@types/markdown-it": "^10.0.2",
103103
"@types/node": "^14.0.0",
104104
"@types/postcss-load-config": "^2.0.1",
105-
"@typescript-eslint/eslint-plugin": "^4.1.0",
106-
"@typescript-eslint/parser": "^4.1.0",
105+
"@typescript-eslint/eslint-plugin": "^5.4.0",
106+
"@typescript-eslint/parser": "^5.4.0",
107107
"@vitejs/plugin-vue": "^1.2.4",
108108
"@vitejs/plugin-vue-jsx": "^1.1.6",
109109
"@vue/babel-plugin-jsx": "^1.0.0",
110110
"@vue/cli-plugin-eslint": "^5.0.0-0",
111111
"@vue/compiler-sfc": "^3.1.0",
112112
"@vue/eslint-config-prettier": "^6.0.0",
113-
"@vue/eslint-config-typescript": "^7.0.0",
113+
"@vue/eslint-config-typescript": "^9.0.0",
114114
"@vue/test-utils": "^2.0.0-0",
115115
"@webpack-cli/serve": "^1.3.1",
116116
"acorn": "^8.0.0",
@@ -141,15 +141,15 @@
141141
"enquire-js": "^0.2.1",
142142
"esbuild": "~0.12.29",
143143
"escape-html": "^1.0.3",
144-
"eslint": "^7.25.0",
144+
"eslint": "^8.3.0",
145145
"eslint-config-prettier": "^8.0.0",
146146
"eslint-plugin-html": "^6.0.0",
147147
"eslint-plugin-import": "^2.24.2",
148-
"eslint-plugin-jest": "^24.3.6",
148+
"eslint-plugin-jest": "^25.3.0",
149149
"eslint-plugin-markdown": "^2.0.0",
150150
"eslint-plugin-no-explicit-type-exports": "^0.12.0",
151-
"eslint-plugin-prettier": "^3.1.0",
152-
"eslint-plugin-vue": "^7.1.0",
151+
"eslint-plugin-prettier": "^4.0.0",
152+
"eslint-plugin-vue": "^8.1.1",
153153
"fast-glob": "^3.2.7",
154154
"fetch-jsonp": "^1.1.3",
155155
"fs-extra": "^10.0.0",
@@ -213,7 +213,7 @@
213213
"through2": "^3.0.0",
214214
"ts-jest": "^26.4.1",
215215
"ts-loader": "^9.1.0",
216-
"typescript": "~4.3.5",
216+
"typescript": "~4.5.2",
217217
"umi-mock-middleware": "^1.0.0",
218218
"umi-request": "^1.3.5",
219219
"url-loader": "^3.0.0",
@@ -222,7 +222,7 @@
222222
"vue-antd-md-loader": "^1.2.1-beta.1",
223223
"vue-clipboard2": "0.3.3",
224224
"vue-draggable-resizable": "^2.1.0",
225-
"vue-eslint-parser": "^7.0.0",
225+
"vue-eslint-parser": "^8.0.0",
226226
"vue-i18n": "^9.1.7",
227227
"vue-infinite-scroll": "^2.0.2",
228228
"vue-jest": "^5.0.0-alpha.3",

plugin/docs/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ export default (options: Options = {}): Plugin => {
1414
const markdownToVue = createMarkdownToVueRenderFn(root, markdown);
1515
return {
1616
name: 'vueToMdToVue',
17-
transform(code, id) {
17+
async transform(code, id) {
1818
if (
1919
(id.endsWith('.vue') && id.indexOf('/demo/') > -1 && id.indexOf('index.vue') === -1) ||
2020
id.indexOf('/examples/App.vue') > -1
2121
) {
2222
const res = vueToMarkdown(code, id);
2323
// transform .md files into vueSrc so plugin-vue can handle it
24-
return { code: res.ignore ? res.vueSrc : markdownToVue(res.vueSrc, id).vueSrc, map: null };
24+
return {
25+
code: res.ignore ? res.vueSrc : (await markdownToVue(res.vueSrc, id)).vueSrc,
26+
map: null,
27+
};
2528
}
2629
},
2730
};

plugin/md/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export default (options: Options = {}): Plugin => {
1212
const markdownToVue = createMarkdownToVueRenderFn(root, markdown);
1313
return {
1414
name: 'mdToVue',
15-
transform(code, id) {
15+
async transform(code, id) {
1616
if (id.endsWith('.md')) {
1717
// transform .md files into vueSrc so plugin-vue can handle it
18-
return { code: markdownToVue(code, id).vueSrc, map: null };
18+
return { code: (await markdownToVue(code, id)).vueSrc, map: null };
1919
}
2020
},
2121
};

plugin/md/markdownToVue.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ interface MarkdownCompileResult {
2323
export function createMarkdownToVueRenderFn(
2424
root: string = process.cwd(),
2525
options: MarkdownOptions = {},
26-
): any {
26+
) {
2727
const md = createMarkdownRenderer(options);
2828

29-
return (src: string, file: string): MarkdownCompileResult => {
29+
return async (src: string, file: string): Promise<MarkdownCompileResult> => {
3030
const relativePath = slash(path.relative(root, file));
3131

3232
const cached = cache.get(src);
@@ -57,7 +57,7 @@ export function createMarkdownToVueRenderFn(
5757
lastUpdated: Math.round(fs.statSync(file).mtimeMs),
5858
};
5959
const newContent = data.vueCode
60-
? genComponentCode(md, data, pageData)
60+
? await genComponentCode(md, data, pageData)
6161
: `
6262
<template><article class="markdown">${html}</article></template>
6363
@@ -69,15 +69,15 @@ ${fetchCode(content, 'style')}
6969

7070
debug(`[render] ${file} in ${Date.now() - start}ms.`);
7171
const result = {
72-
vueSrc: newContent?.trim(),
72+
vueSrc: newContent.trim(),
7373
pageData,
7474
};
7575
cache.set(src, result);
7676
return result;
7777
};
7878
}
7979

80-
function genComponentCode(md: MarkdownRenderer, data: PageData, pageData: PageData) {
80+
async function genComponentCode(md: MarkdownRenderer, data: PageData, pageData: PageData) {
8181
const { vueCode, headers = [] } = data as MarkdownParsedData;
8282
const cn = headers.find(h => h.title === 'zh-CN')?.content;
8383
const us = headers.find(h => h.title === 'en-US')?.content;
@@ -91,7 +91,7 @@ ${vueCode?.trim()}
9191
const script = fetchCode(vueCode, 'script');
9292
const style = fetchCode(vueCode, 'style');
9393
const scriptContent = fetchCode(vueCode, 'scriptContent');
94-
let jsCode = tsToJs(scriptContent)?.trim();
94+
let jsCode = (await tsToJs(scriptContent)).trim();
9595
jsCode = jsCode
9696
? `<script>
9797
${jsCode}

plugin/md/utils/tsToJs.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { transformSync } from '@babel/core';
2-
import { CLIEngine } from 'eslint';
2+
import { ESLint } from 'eslint';
33
import path from 'path';
4-
const engine = new CLIEngine({
4+
const engine = new ESLint({
55
fix: true,
66
useEslintrc: false,
77
baseConfig: require(path.join(process.cwd(), '.eslintrc.js')),
88
});
9-
const tsToJs = (content: string): string => {
9+
const tsToJs = async (content: string): Promise<string> => {
1010
if (!content) {
1111
return '';
1212
}
@@ -21,8 +21,8 @@ const tsToJs = (content: string): string => {
2121
],
2222
],
2323
});
24-
const report = engine.executeOnText(code);
25-
let output = report.results[0].output;
24+
const report = await engine.lintText(code);
25+
let output = report[0].output;
2626
output = output ? output.trim() : output;
2727
return output;
2828
};

site/scripts/genrateRoutes.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const globby = require('globby');
33
const fs = require('fs');
44
const path = require('path');
55
const matter = require('gray-matter');
6-
const { CLIEngine } = require('eslint');
6+
const { ESLint } = require('eslint');
77

88
(async () => {
99
const paths = await globby('components/*/index.*.md');
@@ -30,13 +30,13 @@ export default [
3030
)}
3131
];`;
3232

33-
const engine = new CLIEngine({
33+
const engine = new ESLint({
3434
fix: true,
3535
useEslintrc: false,
3636
baseConfig: require(path.join(process.cwd(), '.eslintrc.js')),
3737
});
3838

39-
const report = engine.executeOnText(TEMPLATE);
39+
const report = await engine.lintText(TEMPLATE);
4040

41-
fs.writeFileSync('site/src/router/demoRoutes.js', report.results[0].output);
41+
fs.writeFileSync('site/src/router/demoRoutes.js', report[0].output);
4242
})();

0 commit comments

Comments
 (0)