国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
eslint
Effect
prettier
Configuring automatic formatting
效果
lint-staged
Home Common Problem Several front-end formatting tools worth knowing in 2023 [Summary]

Several front-end formatting tools worth knowing in 2023 [Summary]

Sep 30, 2022 pm 02:17 PM
javascript vue.js Architecture

Several front-end formatting tools worth knowing in 2023 [Summary]

In the big front-end era, various front-end tool chains are constantly emerging, including eslint, prettier, husky, commitlint etc. Sometimes it’s trouble??? when there are too many things. How to use this correctly is something every front-end developer needs to master. Please get on board? ??

eslint

This front-end engineering project is based on react. The same is true for vue users, except that individual dependency packages are different.

Use the ecological chain of eslint to standardize developers’ specifications for the basic syntax of js/ts. Prevent team members from writing randomly.

The main eslint packages used here are the following:

"eslint": "^8.33.0",  // 這個(gè)是eslint的主包
"eslint-plugin-react": "^7.32.2",  // 這是react基于eslint來(lái)做的語(yǔ)法規(guī)范插件
"eslint-plugin-react-hooks": "^4.6.0", // 這是 react-hooks 語(yǔ)法基于eslint做的插件
"@typescript-eslint/eslint-plugin": "^5.50.0",  // typescript 基于eslint來(lái)做的插件
"@typescript-eslint/parser": "^5.50.0",  // typescript 基于eslint做的語(yǔ)法解析器,使得eslint可以約束ts語(yǔ)法

Use the following statements to follow the dependencies:

pnpm i eslint eslint-plugin-react eslint-plugin-react-hooks @typescript-eslint/parser @typescript-eslint/eslint-plugin -D

Next You need to write the eslint specifications into the configuration file. You can create a .eslintrc.cjs

module.exports = {
    'env': {
        'node': true,   // 標(biāo)志當(dāng)前的環(huán)境,不然使用module.exports 會(huì)報(bào)錯(cuò)
        'es2021': true
    },
    extends: [
      'eslint:recommended',  // 使用eslint推薦的語(yǔ)法規(guī)范
      'plugin:react/recommended',  // react推薦的語(yǔ)法規(guī)范
      'plugin:@typescript-eslint/recommended' // ts推薦的語(yǔ)法規(guī)范
    ],
    parser: '@typescript-eslint/parser',  // 使用解析器來(lái)解析ts的代碼,使得eslint可以規(guī)范ts的代碼
    parserOptions: {
      ecmaFeatures: {
        jsx: true  // 允許使用jsx的語(yǔ)法
      },
      ecmaVersion: 'latest',  // es的版本為最新版本
      sourceType: 'module'  // 代碼的模塊化方式,使用module的模塊方式
    },
    plugins: ['react', '@typescript-eslint', 'react-hooks'],  // 使用對(duì)應(yīng)的react, react-hooks, @typescript-eslint 等插件
    rules: {
      quotes: ['error', 'single'],  // 配置單引號(hào)的規(guī)則,如果不是單引號(hào),報(bào)錯(cuò)
      semi: 'off',  //  不需要使用分號(hào);
      'react/react-in-jsx-scope': 'off'  // 在jsx中不需要導(dǎo)入 react的包
    }
  }

in the root directory of the project. Next, add a command to the scripts of package.json

"lint": "eslint --ext .ts,.tsx,.js,.jsx ./" // 使用eslint 規(guī)范 ts,tsx,js,jsx的代碼

Effect

Several front-end formatting tools worth knowing in 2023 [Summary]

The non-standard format in the code is exposed. Now you can repair and format the code. But in terms of formatting code, prettier does a better job, so let’s use prettier to format the code

prettier

prettier is an open source code formatting package that supports a variety of code writing tools, including common vscode, webstorm, etc., it all supports , so how to integrate it?

Use the following statement to install dependencies:

pnpm i prettier eslint-plugin-prettier eslint-config-prettier

Let me explain below what these packages are used for, otherwise you will install them by mistake

"prettier": "^2.8.3",  // prettier 主包
"eslint-config-prettier": "^8.6.0",  // eslint 和prettier的共同配置
"eslint-plugin-prettier": "^4.2.1",  // 在eslint當(dāng)中,使用prettier為插件,才能一起使用

After installing the dependencies, We also need to add the prettier configuration to eslitrc.cjs as follows:

{
 extends:[
 ...,
+ 'prettier', // prettier
+ 'plugin:prettier/recommended' // prettier推薦的配置  
 ],
+ plugins:[...,'prettier'],
rules: {
+    'prettier/prettier': 'error', // eslint 和prettier 用prettier的錯(cuò)誤
    }
}

Next, add a script to package.json

+ "prettier": "eslint --fix --ext .ts,.tsx,.js,.jsx --quiet ./"

At this time, we also need to configure which files do not need to be code formatted, so create .prettierignore under the root directory and add the following content:

node_modules
package.json
pnpm-lock.yaml
dist

Effect

Several front-end formatting tools worth knowing in 2023 [Summary]

The repair was successful, but a warning was reported here. The solution is as follows:

Add the previous configuration at the end of eslintrc.cjs as follows:

+ settings: {
+    react: {
+      version: 'detect'
+    }
+  }

Several front-end formatting tools worth knowing in 2023 [Summary]

Configuring automatic formatting

Every time I need to execute the script in the terminal, it is a bit complicated. Can I set automatic formatting?

The answer is yes

  1. Open settings

Several front-end formatting tools worth knowing in 2023 [Summary]

  1. Enterfomatter, then select Text Compiler, select prettier-Code formatter

Several front-end formatting tools worth knowing in 2023 [Summary]

    ##Then search
  1. formate on save, select it

Several front-end formatting tools worth knowing in 2023 [Summary]

and the following effect will appear:

Several front-end formatting tools worth knowing in 2023 [Summary]

Press

ctrl s will automatically format the code???

husky

Until the above, Just use code formatting tools and code specification checks. These are local, so we still need to perform prettier operations before committing when submitting the code, so there is no need to do it manually.

Use the script to install the following dependency packages

pnpm i husky -D

We initialize

husky## in the terminal through npx husky install

Several front-end formatting tools worth knowing in 2023 [Summary]#We also need to generate the

pre-commit

hook to execute npm run lint<pre class='brush:php;toolbar:false;'>npx husky add .husky/pre-commit &quot;npm run lint&quot; // 這句話(huà)的意思是說(shuō),在commit之前先執(zhí)行 npm run lint腳本</pre>After the installation is completed, it will be in the .husky directory Add a new file in

pre-commit

Several front-end formatting tools worth knowing in 2023 [Summary]It should be noted that we need to register

in

package.json prepare command, after the project is pnpm i, Huksy can be installed. The command is as follows:<pre class='brush:php;toolbar:false;'>+ &quot;prepare&quot;: &quot;husky install&quot;</pre><blockquote><p>上面咱們是自己手動(dòng) <code>npx husky install的,我們需要讓后面使用咱們配置的人自動(dòng)來(lái)初始化 husky

但是大家如果再深入一步,就會(huì)想到???。既然我內(nèi)容都管控好了,是不是需要把 commit -m &#39;xxx&#39; 中的msg 也管控下呀???

使用下面的命令來(lái)安裝包:

pnpm i commitlint @commitlint/cli @commitlint/config-conventional -D

包意思解析

 "@commitlint/cli": "^17.4.2", // 規(guī)范提交信息
 "@commitlint/config-conventional": "^17.4.2",  // commitlint 常用的msg配置
 "commitlint": "^17.4.2" // commitlint 主包

安裝好這些包后,需要在根目錄添加一個(gè) .commitlintrc.cjs來(lái)配置咱們的commitlint的配置:

module.exports = {
  extends: [&#39;@commitlint/config-conventional&#39;]
}

有了這些配置,commit是否生效呢?

答案是 no, 還需要在git hooks中添加一個(gè)方法

在終端執(zhí)行下面的命令

npx husky add .husky/commit-msg &#39;npx --no-install commitlint --edit "$1"&#39;

然后會(huì)在.husky中生成一個(gè)新的文件commit-msg

Several front-end formatting tools worth knowing in 2023 [Summary]

效果

接下來(lái)就是見(jiàn)證奇跡的時(shí)刻???

Several front-end formatting tools worth knowing in 2023 [Summary]

對(duì)于亂寫(xiě)commit 信息就過(guò)不了哦???

lint-staged

對(duì)于細(xì)心的同學(xué)可能會(huì)發(fā)現(xiàn),我們每一次提交都會(huì) prettier整個(gè)目錄的所有問(wèn)題,大大的降低了咱們編碼的速度。所以咱們還需要做一件事情,那就是 只格式化需要提交的代碼,其他的就不需要格式化了

使用下面命令安裝依賴(lài)

pnpm i lint-staged -D

然后在package.json中新增如下內(nèi)容

+ "lint-staged": {
+     "**/*.{js,jsx,tsx,ts}": [  
+          "eslint --fix"
+       ]
+    }

上面那段腳本的意思是 只對(duì) .js,.jsx, .ts,.tsx 后綴文件進(jìn)行eslint的修復(fù),其他的就不進(jìn)行格式化和修復(fù)了

有了這個(gè),還需要對(duì) pre-commit 這個(gè)鉤子就行修改內(nèi)容

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

- npm run lint
+ npx --no -- lint-staged

如此就大功告成啦???

Several front-end formatting tools worth knowing in 2023 [Summary]

(學(xué)習(xí)視頻分享:web前端入門(mén)

The above is the detailed content of Several front-end formatting tools worth knowing in 2023 [Summary]. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the architecture and working principle of Spring Data JPA? What is the architecture and working principle of Spring Data JPA? Apr 17, 2024 pm 02:48 PM

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

1.3ms takes 1.3ms! Tsinghua's latest open source mobile neural network architecture RepViT 1.3ms takes 1.3ms! Tsinghua's latest open source mobile neural network architecture RepViT Mar 11, 2024 pm 12:07 PM

Paper address: https://arxiv.org/abs/2307.09283 Code address: https://github.com/THU-MIG/RepViTRepViT performs well in the mobile ViT architecture and shows significant advantages. Next, we explore the contributions of this study. It is mentioned in the article that lightweight ViTs generally perform better than lightweight CNNs on visual tasks, mainly due to their multi-head self-attention module (MSHA) that allows the model to learn global representations. However, the architectural differences between lightweight ViTs and lightweight CNNs have not been fully studied. In this study, the authors integrated lightweight ViTs into the effective

Hand-tearing Llama3 layer 1: Implementing llama3 from scratch Hand-tearing Llama3 layer 1: Implementing llama3 from scratch Jun 01, 2024 pm 05:45 PM

1. Architecture of Llama3 In this series of articles, we implement llama3 from scratch. The overall architecture of Llama3: Picture the model parameters of Llama3: Let's take a look at the actual values ??of these parameters in the Llama3 model. Picture [1] Context window (context-window) When instantiating the LlaMa class, the variable max_seq_len defines context-window. There are other parameters in the class, but this parameter is most directly related to the transformer model. The max_seq_len here is 8K. Picture [2] Vocabulary-size and AttentionL

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How steep is the learning curve of golang framework architecture? How steep is the learning curve of golang framework architecture? Jun 05, 2024 pm 06:59 PM

The learning curve of the Go framework architecture depends on familiarity with the Go language and back-end development and the complexity of the chosen framework: a good understanding of the basics of the Go language. It helps to have backend development experience. Frameworks that differ in complexity lead to differences in learning curves.

Vue.js vs. React: Project-Specific Considerations Vue.js vs. React: Project-Specific Considerations Apr 09, 2025 am 12:01 AM

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

Is vue.js hard to learn? Is vue.js hard to learn? Apr 04, 2025 am 12:02 AM

Vue.js is not difficult to learn, especially for developers with a JavaScript foundation. 1) Its progressive design and responsive system simplify the development process. 2) Component-based development makes code management more efficient. 3) The usage examples show basic and advanced usage. 4) Common errors can be debugged through VueDevtools. 5) Performance optimization and best practices, such as using v-if/v-show and key attributes, can improve application efficiency.