? How would you like to use ESLint? ... To check syntax only // 仅检查语法 To check syntax and find problems // 检查语法并发现问题 > To check syntax, find problems, and enforce code style // 检查语法、发现问题并强制执行代码样式
在哪种项目模块规范中使用,我选择第一个
1 2 3 4
? What type of modules does your project use? ... > JavaScript modules (import/export) CommonJS (require/exports) None of these
在哪个框架中使用
1 2 3 4
? Which framework does your project use? ... React > Vue.js None of these
√ Does your project use TypeScript? · No / **Yes** √ Where does your code run? · browser, node
希望如何定义项目的样式,这里看实际需要,因为后面还要配置 Prettier,我选择了第二个
1 2 3 4 5
√ How would you like to define a style for your project? … Use a popular style guide ❯ Answer questions about your style ## next √ How would you like to define a style for your project? · prompt
想用什么格式的配置文件,我选了 Javascript
1 2 3 4
? What format do you want your config file to be in? ... > JavaScript YAML JSON
选择缩进风格,看实际需要,我选择了 Tabs
1 2 3
? What style of indentation do you use? ... > Tabs Spaces
字符串使用双引号还是单引号,看实际需要,我选了单引号
1 2 3
? What quotes do you use for strings? ... Double > Single
使用哪种结束符,Windows 是 CRLF,Unix 是 LF,我这里选择了默认,因为后面在.eslintrc.js改成了不限制,即在 类 Unix 平台和 Windows 平台都不做警示
1 2 3
? What line endings do you use? ... > Unix Windows
是否使用分号,我选择了 No
1
? Do you require semicolons? » No / Yes
接下来会提示需要安装哪些依赖,以及是否立即安装,我选择了 Yes
1 2
@typescript-eslint/eslint-plugin@latest eslint-plugin-vue@latest @typescript-eslint/parser@latest ? Would you like to install them now? » No / Yes
选择包管理工具,看实际需要,我这里选择了 pnpm
1 2 3 4
? Which package manager do you want to use? ... npm yarn > pnpm
随后安装完依赖就会在项目的跟目录下生成.eslintrc.js文件,根据提示,我把后缀改成了.cjs,并且 eslint 已经生效了(如果不生效,建议重启 VS Code)