Skip to content

Commit

Permalink
style: 优化页面显示
Browse files Browse the repository at this point in the history
  • Loading branch information
chuilee committed Sep 2, 2022
1 parent a0e4e74 commit 5305429
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions _posts/2022-09-01-Eslint+prettier+stylelint+commitlint.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ author: "Chuilee"
tags: 前端工程
excerpt_separator: <!--more-->
---

> 网上有很多教怎么搭建的,但却很少记录踩坑的
<!--more-->

### 踩坑
Expand All @@ -27,15 +29,15 @@ chmod a+x commit-msg

增加文件的执行权限。

2. #### 根目录下存在`.prettierrc.js`配置文件,但右键格式化始终不起作用
2. #### 根目录下存在`.prettierrc.js`配置文件,但右键格式化始终不起作用

解决方法:

```shell
npm i -D prettier 或者 npm i -g prettier
```

安装prettier解决
安装 prettier 解决

### 配置 eslint、prettier

Expand All @@ -53,7 +55,7 @@ npm i eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-plugi

1. #### 在根目录下新建`.eslintrc.js`文件

```json
```typescript
/**
* 所需插件
* prettier // 规则见 https://prettier.io/docs/en/options.html
Expand All @@ -72,18 +74,15 @@ npm i eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-plugi
module.exports = {
root: true,
env: {

browser: true,
node: true,
},
/* 优先级低于parse的语法解析配置 */
parserOptions: {

parser: "@typescript-eslint/parser", // Specifies the ESLint parser
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {

// tsx: true, // Allows for the parsing of JSX
jsx: true,
},
Expand All @@ -97,7 +96,6 @@ module.exports = {
],
plugins: ["react"],
rules: {

"no-console": process.env.NODE_ENV === "production" ? 1 : 0,
"no-debugger": process.env.NODE_ENV === "production" ? 1 : 0,
eqeqeq: 2, // 要求使用 === 和 !==
Expand Down Expand Up @@ -125,10 +123,9 @@ module.exports = {
},
overrides: [
{

files: ["**/__tests__/*.{j,t}s?(x)"],
env: {

mocha: true,
},
},
Expand All @@ -138,7 +135,7 @@ module.exports = {

2. #### 在根目录下建立 prettier 配置文件: `.prettierrc.js`

```javascript
```typescript
module.exports = {
printWidth: 100, // 单行输出(不折行)的(最大)长度
tabWidth: 2, // 每个缩进级别的空格数
Expand Down Expand Up @@ -167,7 +164,7 @@ npm i stylelint stylelint-scss stylelint-config-standard-scss stylelint-config-p

#### 根目录下新增 `**.stylelintrc.js**`文件

```
```typescript
module.exports = {
processors: [],
plugins: [],
Expand Down Expand Up @@ -231,18 +228,17 @@ npx --no-install commitlint --config commitlint.config.js --edit $1

根目录创建**commitlint.config.js**

```json
```typescript
module.exports = { extends: ['@commitlint/config-conventional'] }
```

根目录创建**.lintstagedrc.js**

```json
```typescript
module.exports = {
'*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
'*.md': ['prettier --write'],
'*.{scss,less,styl,html}': ['stylelint --fix', 'prettier --write'],
'*.vue': ['eslint --fix', 'prettier --write', 'stylelint --fix'],
};
```

0 comments on commit 5305429

Please sign in to comment.