1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const eslint_1 = require("eslint");
|
4 | const utils_1 = require("./utils");
|
5 | const cli = new eslint_1.CLIEngine({
|
6 | baseConfig: {
|
7 | extends: ['plugin:taro/transformer']
|
8 | },
|
9 | rules: {
|
10 | 'react/no-multi-comp': [2, { ignoreStateless: false }]
|
11 | },
|
12 | plugins: ['react'],
|
13 | useEslintrc: false,
|
14 | parser: 'babel-eslint',
|
15 | parserOptions: {
|
16 | ecmaVersion: 2018,
|
17 | ecmaFeatures: {
|
18 | jsx: true,
|
19 | legacyDecorators: true
|
20 | }
|
21 | },
|
22 | settings: {
|
23 | react: {
|
24 | pragma: 'Taro',
|
25 | version: 'detect'
|
26 | }
|
27 | }
|
28 | });
|
29 | exports.eslintValidation = () => {
|
30 | return {
|
31 | visitor: {
|
32 | Program(_, state) {
|
33 | const { file: { code } } = state;
|
34 | const report = cli.executeOnText(code);
|
35 | if (report.errorCount > 0) {
|
36 | for (const result of report.results) {
|
37 | for (const msg of result.messages) {
|
38 | const err = utils_1.codeFrameError({
|
39 | start: {
|
40 | line: msg.line,
|
41 | column: msg.column
|
42 | },
|
43 | end: {
|
44 | line: msg.endLine,
|
45 | column: msg.endColumn
|
46 | }
|
47 | }, msg.message);
|
48 |
|
49 | console.warn('\n' + `ESLint(${msg.ruleId}) 错误:` + err.message.replace('Declare only one React component per file', '一个文件只能定义一个 Taro 类或 Taro 函数式组件') + '\n');
|
50 | }
|
51 | }
|
52 | }
|
53 | }
|
54 | }
|
55 | };
|
56 | };
|
57 |
|
\ | No newline at end of file |