前端规范前端规范
首页
  • HTML 编码规范
  • CSS 编码规范
  • JavaScript 编码规范
  • Typescript 编码规范
  • Node 编码规范
  • Git 规范
  • 文档规范
  • CHANGELOG 规范
  • eslint-config-fd
  • web-fe-stylelint
  • web-fe-commitlint
  • web-fe-markdownlint
  • eslint-plugin-fe
  • web-fe-lint
首页
  • HTML 编码规范
  • CSS 编码规范
  • JavaScript 编码规范
  • Typescript 编码规范
  • Node 编码规范
  • Git 规范
  • 文档规范
  • CHANGELOG 规范
  • eslint-config-fd
  • web-fe-stylelint
  • web-fe-commitlint
  • web-fe-markdownlint
  • eslint-plugin-fe
  • web-fe-lint
  • NPM包

    • eslint-config-fd
    • web-fe-stylelint
    • web-fe-commitlint
    • web-fe-markdownlint
    • eslint-plugin-fe

eslint-plugin-fe

除了本包,你需要同时安装 ESlint

npm install eslint-plugin-fe eslint --save-dev

使用

引入插件

// .eslintrc.js
module.exports = {
  plugin: ['eslint-plugin-fe'],
  rules: {
    'eslint-plugin-fe/no-secret-info': 'error',
  },
};

使用 presets

// .eslintrc.js
module.exports = {
  extends: 'plugin:eslint-plugin-fe/recommended',
};

支持的规则

no-broad-semantic-versioning

不要在 package.json 中使用太过宽泛的版本指定方式,包括 *、x 和 > x 。

规则内容

参照 https://docs.npmjs.com/about-semantic-versioning。

使用 *、 x 和 > x 指定版本会被警告。

no-http-url

推荐将 HTTP 链接换为 HTTPS 链接。

规则内容

错误代码示例:

var test = 'http://github.com';
var jsx = <img src="http://github.com">;

何时不适用

如果你的网站只支持 HTTP 时。

no-js-in-ts-project

不推荐在项目中同时存在 JS 和 TS 文件。

规则内容

错误示例,TS 项目中包含 JS 文件:

.
├── index.ts
├── home.js
└── tsconfig.json

正确示例:

.
├── index.ts
├── home.ts
└── tsconfig.json

规则选项

默认当存在 commitlint.config.js, eslintrc.js, prettierrc.js, stylelintrc.js 文件时不会报错,支持自定义设置文件白名单。

no-secret-info

不在代码中直接通过纯文本值设置 password token 和 secret 信息。

规则内容

在包含 password token and secret 名称的 key 中禁止使用纯文本值。

错误代码示例:

var accessKeySecret = 'xxxx';

var client = {
  accessKeyToken: 'xxxx',
};

正确代码示例:

var accessKeySecret = process.env.ACCESS_KEY_SECRET;

var client = {
  accessKeyToken: process.env.ACCESS_KEY_SECRET,
};
Prev
web-fe-markdownlint