The background,

The company project needed to add ESLint validation. Due to the large number of projects and the fact that some old pages had not been updated for a long time, the project team agreed that from now on, new pages would have ESLint validation and old pages would be ignored.

Second, the implementation

1. What is eslintignore for?

When ESLint runs, it looks for an.eslintignore file in the current working directory before determining which files to detect. If the file is found, these preferences will be applied when traversing the directory.

Eslint checks for files to ignore by looking for the eslintignore key in the.eslintignore file or in the package.json file

2. How to define eslintignore

(1) Create one in the project root directory.eslintignoreFiles tell ESLint to ignore specific files and directories..eslintignoreThe file is a plain text file in which each line is a glob pattern indicating which paths should be ignored for detection.

Glob patterns refer to simplified regular expressions used by shells.

(2) The configuration is as follows:
/node_modules
/dist
/src/assets/js
/src/views
/package-lock.json
.DS_Store
vue.config.js
Copy the code
(3) Rules to follow,Refer to gitignore configuration rules
/hello/* // starts with a "/", matching the directory level relative to the '.gitignore 'file itself. Hello // / ends with "/", matching all directories (excluding files) in any level of the Hello directory.* // Matches with Hello. Hello /* // matches all directories and files in the hello directory! /foo/bar // excludes all contents except directory foo/bar **/foo // the leading ' '** *' 'matches in all directories, the same as foo/** // the following' '/** *' matches in all contents. Matches all files under directory 'foo'Copy the code

Note that:

An optional prefix “!” It negates patterns; Any matching files that were excluded from the previous schema are included again. If the parent directory of the file is excluded, the file cannot be re-included.

For example, you want to ignore all directories and files under SRC, except the SRC /views/hello directory. SRC /* / SRC /views/ / SRC /views/* / exclude SRC /views/* / SRC /views/hello/ / SRC /views/hello all directories are included againCopy the code