Additional ESLint's rules for Node.js
$ npm install --save-dev eslint eslint-plugin-node
>=8.10.0
>=5.16.0
Note: It recommends a use of the "engines" field of package.json. The "engines" field is used by node/no-unsupported-features/*
rules.
.eslintrc.json (An example)
{
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"parserOptions": {
// Only ESLint 6.2.0 and later support ES2020.
"ecmaVersion": 2020
},
"rules": {
"node/exports-style": ["error", "module.exports"],
"node/file-extension-in-import": ["error", "always"],
"node/prefer-global/buffer": ["error", "always"],
"node/prefer-global/console": ["error", "always"],
"node/prefer-global/process": ["error", "always"],
"node/prefer-global/url-search-params": ["error", "always"],
"node/prefer-global/url": ["error", "always"],
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error"
}
}
package.json (An example)
{
"name": "your-module",
"version": "1.0.0",
"type": "commonjs",
"engines": {
"node": ">=8.10.0"
}
}
Rule ID | Description | |
---|---|---|
node/handle-callback-err | require error handling in callbacks | |
node/no-callback-literal | ensure Node.js-style error-first callback pattern is followed | |
node/no-exports-assign | disallow the assignment to exports |
|
node/no-extraneous-import | disallow import declarations which import extraneous modules |
|
node/no-extraneous-require | disallow require() expressions which import extraneous modules |
|
node/no-missing-import | disallow import declarations which import non-existence modules |
|
node/no-missing-require | disallow require() expressions which import non-existence modules |
|
node/no-new-require | disallow new operators with calls to require |
|
node/no-path-concat | disallow string concatenation with __dirname and __filename |
|
node/no-process-exit | disallow the use of process.exit() |
|
node/no-unpublished-bin | disallow bin files that npm ignores |
|
node/no-unpublished-import | disallow import declarations which import private modules |
|
node/no-unpublished-require | disallow require() expressions which import private modules |
|
node/no-unsupported-features/es-builtins | disallow unsupported ECMAScript built-ins on the specified version |
|
node/no-unsupported-features/es-syntax | disallow unsupported ECMAScript syntax on the specified version |
|
node/no-unsupported-features/node-builtins | disallow unsupported Node.js built-in APIs on the specified version |
|
node/process-exit-as-throw | make process.exit() expressions the same code path as throw |
|
node/shebang | suggest correct usage of shebang |
|
Rule ID | Description | |
---|---|---|
node/no-deprecated-api | disallow deprecated APIs |
|
Rule ID | Description | |
---|---|---|
node/callback-return | require return statements after callbacks |
|
node/exports-style | enforce either module.exports or exports |
|
node/file-extension-in-import | enforce the style of file extensions in import declarations |
|
node/global-require | require require() calls to be placed at top-level module scope |
|
node/no-mixed-requires | disallow require calls to be mixed with regular variable declarations |
|
node/no-process-env | disallow the use of process.env |
|
node/no-restricted-import | disallow specified modules when loaded by import declarations |
|
node/no-restricted-require | disallow specified modules when loaded by require |
|
node/no-sync | disallow synchronous methods | |
node/prefer-global/buffer | enforce either Buffer or require("buffer").Buffer |
|
node/prefer-global/console | enforce either console or require("console") |
|
node/prefer-global/process | enforce either process or require("process") |
|
node/prefer-global/text-decoder | enforce either TextDecoder or require("util").TextDecoder |
|
node/prefer-global/text-encoder | enforce either TextEncoder or require("util").TextEncoder |
|
node/prefer-global/url-search-params | enforce either URLSearchParams or require("url").URLSearchParams |
|
node/prefer-global/url | enforce either URL or require("url").URL |
|
node/prefer-promises/dns | enforce require("dns").promises |
|
node/prefer-promises/fs | enforce require("fs").promises |
These rules have been deprecated in accordance with the deprecation policy, and replaced by newer rules:
Rule ID | Replaced by |
---|---|
node/no-hide-core-modules | (nothing) |
node/no-unsupported-features | node/no-unsupported-features/es-syntax and node/no-unsupported-features/es-builtins |
This plugin provides three configs:
plugin:node/recommended
considers both CommonJS and ES Modules. If "type":"module"
field existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers *.mjs
files as ES Modules and *.cjs
files as CommonJS.plugin:node/recommended-module
considers all files as ES Modules.plugin:node/recommended-script
considers all files as CommonJS.Those preset config:
process.exit()
.{ecmaVersion: 2019}
and etc into parserOptions
.globals
.plugins
.no-missing-import
/ no-missing-require
rules don't work with nested folders in SublimeLinter-eslinteslint-plugin-node
follows semantic versioning and ESLint's Semantic Versioning Policy.
Welcome contributing!
Please use GitHub's Issues/PRs.
npm test
runs tests and measures coverage.npm run coverage
shows the coverage result of npm test
command.npm run clean
removes the coverage result of npm test
command.最近在研究怎样在webpack打包中加入代码格式审查,看到一大堆各种莫名其妙的eslint相关扩展插件,头大,不明所以,随花了两天时间研究了一下相应的操作; 一般我们使用eslint是想格式化我们的代码,使它更规范,大家能约定熟成,便于统一项目代码风格,减少不必要的格式错误; 一般理想的状态是,大家提交代码之前一会自动格式化,并检查格式错误,给予提示; git钩子husky hsuky的作用是在我
全局安装eslint,同时也需要安装其他几个包: F:\mywork\vue\mpvue1st>cnpm install -g eslint F:\mywork\vue\mpvue1st>cnpm install -g eslint-plugin-html F:\mywork\vue\mpvue1st>cnpm install -g babel-eslint F:\mywork\vue\mpvue
ESLint 配置 一、eslint 安装 1、全局安装 npm i -g eslint 全局安装的好处是,在任何项目我们都可以使用eslint的全局命令进行代码规则操作,但是这对我们的意义并不大,后续会详细介绍; 全局安装之后,要求相关的eslint插件页必须全局安装,这对多人开发项目来说会比项目安装更加繁琐。所以,我们这里采用在项目上安装eslint: 2、项目安装 npm i -D esli
vue工程项目中使用@vue/eslint-config-standard包,其依赖eslint-plugin-import,但是由于最近eslint-plugin-import包的作者升级了版本,导致项目build会报错: Syntax Error: Thread Loader (Worker 0) Cannot find module 'array.prototype.flatmap' Ref
error @typescript-eslint/eslint-plugin@5.11.0: The engine "node" is incompatible with this module. Expected version "^12.22.0 || ^14.17.0 || >=16.0.0". Got "12.19.0" error Found incompatible module. i
eslint-plugin-vue@8.7.1: The engine “node” is incompatible with this module. Expected version “^12.22.0 || ^14.17.0 || >=16.0.0”. Got “14.15.3” 输入运行以下命令: yarn config set ignore-engines true 重新 yarn in
问题描述 vue项目在引入eslint代码质量检查工具时报错Cannot find module 'eslint-plugin-vue',提示缺少依赖,在按照官方文档要求安装之后错误仍然未解决,此时node_mudules中已经有了eslint-plugin-vue这个包, 解决方案 全局安装eslint-plugin-vue这个包。 npm i -g eslint-plugin-vue 报错原
在 egg 项目中,初次安装 npm 包的时候,报错如下: Oops! Something went wrong! :( ESLint: 5.16.0. ESLint couldn't find the plugin "eslint-plugin-jsdoc". This can happen for a couple different reasons: 1. If ESLint is in
报错信息 Oops! Something went wrong! :( ESLint couldn't find the plugin "eslint-plugin-@typescript-eslint". This can happen for a couple different reasons: 1. If ESLint is installed globally, then make
eslint 报错 [vue/no-unused-vars] ‘index’ is defined but never used. 打开vscode,找到设置,搜索 setting.json 写入 如下配置,“vetur.validation.template”: false, 保存关闭后,重新打开
https://ask.csdn.net/questions/1963567 如果尝试了网上的各种引入插件和配置VScode Eslint 后工作空间仍然不提示,不自动根据Eslint规则,进行代码修复,请看下边操作。 // 错误场景为,总是提示找不到@typescript-eslint/eslint-plugin,不管是删除node_modules文件夹重新install、还是和同事对各个环节的
前端项目启动时报错,找不到 'eslint-webpack-plugin’模块。 使用 npm i下载依赖报错,则有可能是node和npm的版本问题。 可以尝试下载nvm,将node版本改为10.X或12.X。
eslint-plugin-sql SQL linting rules for ESLint. In its current form, the plugin has been designed and tested to work with Postgres codebase. eslint-plugin-sql Installation Configuration Settings place
eslint-plugin-vue Official ESLint plugin for Vue.js �� Documentation See the official website. ⚓ Versioning Policy This plugin is following Semantic Versioning and ESLint's Semantic Versioning Policy.
eslint-plugin-ember An ESLint plugin that provides a set of rules for Ember applications based on commonly known good practices. ❗️ Requirements ESLint >= 6 Node.js 10.* || 12.* || >= 14 �� Usage 1. I
eslint-plugin-wxml 为 lint 微信小程序 wxml 文件而开发的 eslint 插件,可使用 eslint 来检查微信小程序项目内的 wxml 代码 当开发者使用 VSCode 或者 Webstorm 时可以得到代码错误提示,目前支持的 lint 规则如下: 1. wxml/colon-style-event-binding 强制使用:冒号隔开时间绑定 2. wxml/emp
eslint-plugin-optimize-regex Optimize regex literals Installation You'll first need to install ESLint: npm i eslint --save-dev Next, install eslint-plugin-optimize-regex: npm install eslint-plugin-opt
ESLint plugin for React Native React Native specific linting rules for ESLint. This repository is structured like (and contains code from) the excellent eslint-plugin-react. Installation Install ESLin