Skip to content

Commit 574511a

Browse files
committed
eslint 校验
1 parent 0d7c3c3 commit 574511a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+592
-497
lines changed

.eslintignore

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ webpack/**/*
1818
**/webpack
1919
**/webpack/**/*
2020
**/webpack/**/*
21+
22+
23+
@babel
24+
@babel/*
25+
@babel/**/*
26+
27+
2128

2229

2330

.eslintrc.js

+52-34
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,30 @@ module.exports = {
1818
es6: true,
1919
mocha: true,
2020
browser: true,
21-
es2021: true,
21+
es2021: true
2222
},
23-
plugins: [
24-
'react',
25-
'jsx-a11y',
26-
'import',
27-
'@babel',
28-
29-
// 'prettier'
30-
],
31-
parser: '@babel/eslint-parser',
23+
plugins: ["react", "jsx-a11y", "import", "@babel", "react-hooks", "prettier"],
24+
parser: "@babel/eslint-parser",
3225
parserOptions: {
3326
requireConfigFile: false,
3427
// parser: "@babel/eslint-parser",
3528
ecmaVersion: 6,
36-
sourceType: 'module',
29+
sourceType: "module",
3730
ecmaFeatures: {
3831
jsx: true,
3932
modules: true,
40-
experimentalObjectRestSpread: true,
33+
experimentalObjectRestSpread: true
4134
},
4235
},
4336

4437
extends: [
45-
'eslint:recommended',
46-
'plugin:react/recommended',
38+
"eslint:recommended",
39+
"plugin:react/recommended",
4740
// 'prettier',
48-
'plugin:prettier/recommended',
41+
"plugin:prettier/recommended"
4942
],
5043

51-
settings: { react: { pragma: 'React', version: '15.6.1' } },
44+
settings: { react: { pragma: "React", version: "15.6.1" } },
5245

5346
// 这里可以进行自定义规则配置
5447
// key:规则代号
@@ -57,28 +50,53 @@ module.exports = {
5750
// "warn" or 1 - 将规则视为一个警告(不会影响退出码),只警告,不会退出程序
5851
// "error" or 2 - 将规则视为一个错误 (退出码为1),报错并退出程序
5952
rules: {
60-
'no-debugger': 0,
61-
'react/prop-types': 0,
62-
'no-prototype-builtins': 0,
63-
'comma-dangle': 0,
64-
'react/jsx-uses-vars': 1,
65-
'react/display-name': 1,
66-
'no-unused-vars': 'warn',
67-
'no-console': 'warn',
68-
'no-unexpected-multiline': 'warn',
53+
"@babel/object-curly-spacing": "off",
54+
"prettier/prettier": 2,
55+
"no-debugger": 0,
56+
"react/prop-types": 0,
57+
"no-prototype-builtins": 0,
58+
"react/jsx-uses-vars": 1,
59+
"react/display-name": 1,
60+
"no-unused-vars": "warn",
61+
"no-console": "warn",
62+
"no-unexpected-multiline": "warn",
6963
// // 自定义规则 - 其实上面集成后有很多内置的规则, 这里可以进行规则的一些修改
7064
// 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', // 上线环境用打印就报警告, 开发环境关闭此规则
7165
// 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', // debugger可以终止代码执行
7266
// 'no-multiple-empty-lines': 'off', // 不允许有连续多行空行(关闭规则)
73-
// 'no-undef': 1, //不能有未定义的变量
74-
eqeqeq: ['error', 'always'],
67+
"no-undef": 1, //不能有未定义的变量
68+
eqeqeq: ["error", "always"],
7569
// 'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
76-
'no-undef': 'error',
7770
// 'no-void': 2, //禁用void操作符
78-
'@babel/new-cap': 'error',
79-
'@babel/no-invalid-this': 'error',
80-
'@babel/no-unused-expressions': 'error',
81-
'@babel/object-curly-spacing': 'error',
82-
'@babel/semi': 'error',
71+
"@babel/new-cap": "warn",
72+
"@babel/no-invalid-this": "warn",
73+
"@babel/no-unused-expressions": "warn",
74+
"@babel/semi": "warn",
75+
// 禁止不必要的转义字符
76+
"no-useless-escape": 1,
77+
"react/jsx-uses-react": 2, // 屏蔽"React" is defined but never used错误
78+
"comma-dangle": ["off"], // 不允许最后多余的逗号
79+
"react-hooks/rules-of-hooks": "warn", // 检查Hook的规则
80+
"max-params": ["warn", 8], // 方法最多8个参数
81+
"react-hooks/exhaustive-deps": "warn", // 检查effect的依赖
82+
"max-nested-callbacks": ["warn", 4], // 循环最多4层,超过4层警告
83+
"brace-style": ["off", "1tbs"],
84+
"react/no-string-refs": "warn", // string类型的refs报warn
85+
"no-unreachable-loop": "off",
86+
"eol-last": ["error", "always"], // 文件末尾需要多空一行
87+
// 先off掉
88+
"react-hooks/exhaustive-deps": "warn", // 检查effect的依赖
89+
"react/no-children-prop": 1,
90+
eqeqeq: 1,
91+
// 数组和对象键值对最后一个逗号, never参数:不能带末尾的逗号, always参数:必须带末尾的逗号,
92+
// always-multiline:多行模式必须带逗号,单行模式不能带逗号
93+
"comma-dangle": [1, "never"],
94+
// 控制逗号前后的空格
95+
"comma-spacing": [1, { before: false, after: true }],
96+
// 控制逗号在行尾出现还是在行首出现
97+
// http://eslint.org/docs/rules/comma-style
98+
"comma-style": [1, "last"]
99+
// 数组和对象键值对最后一个逗号, never参数:不能带末尾的逗号, always参数:必须带末尾的逗号,
100+
// always-multiline:多行模式必须带逗号,单行模式不能带逗号
83101
},
84-
}
102+
};

.prettierignore

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ coverage
44

55
# Ignore all HTML files:
66
*.html
7+
**/*.min.js
8+
**/*.min.css
9+
10+
.idea/
11+
node_modules/
12+
dist/
13+
build/

.prettierrc.js

+49-47
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,74 @@
77
* @Description:
88
*/
99
module.exports = {
10-
'prettier/prettier': [
11-
'error',
12-
{
13-
singleQuote: true,
14-
parser: 'flow',
15-
},
16-
],
10+
1711
singleQuote: false, // 使用单引号
1812
jsxSingleQuote: false, // jsx中使用单引号
19-
// semi: false, // 不加分号
20-
// trailingComma: 'none', // 结尾处不加逗号
21-
// htmlWhitespaceSensitivity: 'ignore', // 忽略'>'下落问题
22-
// printWidth: 1800, //单行长度
23-
// tabWidth: 1000, //缩进长度
24-
// useTabs: false, //使用空格代替tab缩进
25-
// semi: true, //句末使用分号
26-
// singleQuote: true, //使用单引号
27-
// quoteProps: 'as-needed', //仅在必需时为对象的key添加引号
13+
// semi: false, // 不加分号
14+
trailingComma: 'none', // 结尾处不加逗号
15+
// htmlWhitespaceSensitivity: 'ignore', // 忽略'>'下落问题
16+
// printWidth: 4, //单行长度
17+
// tabWidth: 80, //缩进长度
18+
// useTabs: false, //使用空格代替tab缩进
19+
// semi: true, //句末使用分号
20+
// singleQuote: true, //使用单引号
21+
// quoteProps: 'as-needed', //仅在必需时为对象的key添加引号
2822

29-
// trailingComma: 'all', //多行时尽可能打印尾随逗号
30-
// bracketSpacing: true, //在对象前后添加空格
31-
// jsxBracketSameLine: true, //多属性html标签的‘>’折行放置
32-
// arrowParens: 'always', //单参数箭头函数参数周围使用圆括号
33-
// requirePragma: false, //无需顶部注释即可格式化
34-
// insertPragma: false, //在已被preitter格式化的文件顶部加上标注
35-
// htmlWhitespaceSensitivity: 'ignore', //对HTML全局空白不敏感
36-
// vueIndentScriptAndStyle: false, //不对vue中的script及style标签缩进
37-
// endOfLine: 'lf', //结束行形式
38-
// embeddedLanguageFormatting: 'auto', //对引用代码进行格式化
39-
// 'prettier.proseWrap': 'preserve', // 是否要换行
40-
// 'vetur.format.defaultFormatter.js': 'prettier', // vetur 使用 prettier格式化代码
41-
// 'prettier.printWidth': 30, // 超过最大值换行
23+
// trailingComma: 'all', //多行时尽可能打印尾随逗号
24+
// bracketSpacing: true, //在对象前后添加空格
25+
// jsxBracketSameLine: true, //多属性html标签的‘>’折行放置
26+
// arrowParens: 'always', //单参数箭头函数参数周围使用圆括号
27+
// requirePragma: false, //无需顶部注释即可格式化
28+
// insertPragma: false, //在已被preitter格式化的文件顶部加上标注
29+
// htmlWhitespaceSensitivity: 'ignore', //对HTML全局空白不敏感
30+
// vueIndentScriptAndStyle: false, //不对vue中的script及style标签缩进
31+
// endOfLine: 'lf', //结束行形式
32+
// embeddedLanguageFormatting: 'auto', //对引用代码进行格式化
33+
// 'proseWrap': 'preserve', // 是否要换行
34+
// 'vetur.format.defaultFormatter.js': 'prettier', // vetur 使用 prettier格式化代码
35+
// 'printWidth': 30, // 超过最大值换行
4236

43-
// 'prettier.tabWidth': 2, // 缩进字节数
37+
// 'tabWidth': 2, // 缩进字节数
4438

45-
// 'prettier.useTabs': false, // 缩进不使用tab,使用空格
39+
// 'useTabs': false, // 缩进不使用tab,使用空格
4640

47-
// 'prettier.semi': false, // 句尾添加分号
41+
// 'semi': false, // 句尾添加分号
4842

49-
// 'prettier.singleQuote': false, // 使用单引号代替双引号
43+
// 'singleQuote': false, // 使用单引号代替双引号
5044

51-
// 'prettier.proseWrap': 'preserve', // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行
45+
// 'proseWrap': 'preserve', // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行
5246

53-
// 'prettier.arrowParens': 'avoid', // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号
47+
// 'arrowParens': 'avoid', // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号
5448

55-
// 'prettier.bracketSpacing': true, // 在对象,数组括号与文字之间加空格 "{ foo: bar }"
49+
// 'bracketSpacing': true, // 在对象,数组括号与文字之间加空格 "{ foo: bar }"
5650

57-
// 'prettier.endOfLine': 'auto', // 结尾是 \n \r \n\r auto
51+
// 'endOfLine': 'auto', // 结尾是 \n \r \n\r auto
5852

59-
// 'prettier.eslintIntegration': false, //不让prettier使用eslint的代码格式进行校验
53+
// 'eslintIntegration': false, //不让prettier使用eslint的代码格式进行校验
6054

61-
// 'prettier.htmlWhitespaceSensitivity': 'ignore',
55+
// 'htmlWhitespaceSensitivity': 'ignore',
6256

63-
// 'prettier.ignorePath': '.prettierignore', // 不使用prettier格式化的文件填写在项目的.prettierignore文件中
57+
// 'ignorePath': '.prettierignore', // 不使用prettier格式化的文件填写在项目的.prettierignore文件中
6458

65-
// 'prettier.jsxBracketSameLine': false, // 在jsx中把'>' 单独放一行
59+
// 'jsxBracketSameLine': false, // 在jsx中把'>' 单独放一行
6660

67-
// 'prettier.jsxSingleQuote': false, // 在jsx中使用单引号代替双引号
61+
// 'jsxSingleQuote': false, // 在jsx中使用单引号代替双引号
6862

69-
// 'prettier.parser': 'babylon', // 格式化的解析器,默认是babylon
63+
// 'parser': 'babylon', // 格式化的解析器,默认是babylon
7064

71-
// 'prettier.requireConfig': false, // Require a 'prettierconfig' to format prettier
65+
// 'requireConfig': false, // Require a 'prettierconfig' to format prettier
7266

73-
// 'prettier.stylelintIntegration': false, //不让prettier使用stylelint的代码格式进行校验
67+
// 'stylelintIntegration': false, //不让prettier使用stylelint的代码格式进行校验
7468

75-
// 'prettier.trailingComma': 'es5', // 在对象或数组最后一个元素后面是否加逗号(在ES5中加尾逗号)
69+
// 'trailingComma': 'es5', // 在对象或数组最后一个元素后面是否加逗号(在ES5中加尾逗号)
7670

77-
// 'prettier.tslintIntegration': false, // 不让prettier使用tslint的代码格式进行校验
71+
// 'tslintIntegration': false, // 不让prettier使用tslint的代码格式进行校验
72+
// printWidth: 100, // 代码宽度建议不超过100字符
73+
// tabWidth: 10, // tab缩进2个空格
74+
// semi: false, // 末尾分号
75+
// singleQuote: true, // 单引号
76+
// jsxSingleQuote: true, // jsx中使用单引号
77+
// trailingComma: 'es5', // 尾随逗号
78+
// arrowParens: 'avoid', // 箭头函数仅在必要时使用()
79+
// htmlWhitespaceSensitivity: 'css', // html空格敏感度
7880
}

bin/cmd.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import moment from 'moment'
1313
export default class Cmd {
1414
text = ''
1515

16-
runNodeModule(moduleName, params, options) {
16+
runNodeModule (moduleName, params, options) {
1717
if (os.type() == 'Windows_NT' && !moduleName.match(/\.cmd$/)) {
1818
moduleName += '.cmd'
1919
}
2020
return this.run(moduleName, params, options)
2121
}
2222

23-
run(command, params, options) {
23+
run (command, params, options) {
2424
this.text = ''
2525
// options = Object.assign(options || {}, { cwd: this.cfg.cwd });
2626
return new Promise((resolve, reject) => {

bin/index.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import path from 'path'
1111
import os from 'os'
1212
import { Worker } from 'worker_threads'
1313
import { copyFile, watchFile, readWriteFiles } from '../webpack/utils'
14+
import { compiler } from '../webpack'
1415
import { spawn, SpawnOptions } from 'child_process'
1516
import kill from 'kill-port' // 杀死端口包
1617
import { execute, iSportTake } from './cmd' // 杀死端口包
@@ -52,14 +53,14 @@ if (isEnvDevelopment && isSsr) {
5253
readWriteFiles({
5354
from: path.join(process.cwd(), '/server/**/*').replace(/\\/gi, '/'),
5455
to: path.join(process.cwd(), '/dist/server').replace(/\\/gi, '/'),
55-
transform(content, absoluteFrom) {
56+
transform (content, absoluteFrom) {
5657
let reg = /.jsx|.js$/g
5758
if (reg.test(absoluteFrom)) {
5859
return $ResolveAlias.alias(content.toString(), '')
5960
}
6061
return content
6162
},
62-
async callback() {
63+
async callback () {
6364
if (child && child.kill) {
6465
child.kill()
6566
}
@@ -81,9 +82,13 @@ if (isEnvDevelopment && isSsr) {
8182
})
8283
}
8384

84-
// if (isEnvDevelopment && !isSsr) {
85-
// execute(process.platform === 'win32' ? 'npm.cmd' : 'npm', [
86-
// 'run',
87-
// 'ssr:dev',
88-
// ]);
89-
// }
85+
if (isEnvDevelopment && !isSsr) {
86+
execute("cross-env target='client' npx babel-node -r @babel/register ./server/index.js -r dotenv/config dotenv_config_path=.env.development",);
87+
}
88+
89+
90+
if (isEnvProduction && !isSsr) {
91+
compiler()
92+
93+
94+
}

client/App/App.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* @FilePath: /react-loading-ssr/client/App/App.js
77
* @Description:
88
*/
9-
import React, {Component} from "react";
9+
import React, { Component } from "react";
1010
import PropTypes from "prop-types";
11-
import {Provider} from "react-redux";
11+
import { Provider } from "react-redux";
1212
import Routers from "@/router";
1313
import "./App.less";
1414
import "@/assets/css/base.less";
@@ -25,7 +25,7 @@ const App = (props) => {
2525
d,
2626
e,
2727
f,
28-
sadfasdfasdfsadfasdfasdfasdfasdfsdf,
28+
sadfasdfasdfsadfasdfasdfasdfasdfsdf
2929
} = props;
3030
return (
3131
<Provider store={store}>

client/App/CreateApp.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* @FilePath: /react-loading-ssr/client/App/CreateApp.js
77
* @Description:
88
*/
9-
import React, {Component} from "react";
10-
import Loadable, {Capture} from "@/component/Loadable";
9+
import React, { Component } from "react";
10+
import Loadable, { Capture } from "@/component/Loadable";
1111
import PropTypes from "prop-types";
1212
import App from "./App.js";
1313
import "./App.less";
@@ -16,11 +16,11 @@ let {
1616
NODE_ENV, // 环境参数
1717
WEB_ENV, // 环境参数
1818
target, // 环境参数
19-
htmlWebpackPluginOptions = "",
19+
htmlWebpackPluginOptions = ""
2020
} = process.env; // 环境参数
2121

2222
const CreateApp = (props = {}) => {
23-
const {modules = []} = props;
23+
const { modules = [] } = props;
2424

2525
return target === "ssr" ? (
2626
<Capture
@@ -36,6 +36,6 @@ const CreateApp = (props = {}) => {
3636
};
3737

3838
CreateApp.propTypes = {
39-
modules: PropTypes.object,
39+
modules: PropTypes.object
4040
};
4141
export default CreateApp;

0 commit comments

Comments
 (0)