- 浏览: 480406 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (502)
- Java (70)
- Linux (10)
- 数据库 (38)
- 网络 (10)
- WEB (13)
- JSP (4)
- 互联网 (71)
- JavaScript (30)
- Spring MVC (19)
- HTML (13)
- CSS (3)
- AngularJS (18)
- Redis (5)
- Bootstrap CSS (1)
- ZooKeeper (4)
- kafka (6)
- 服务器缓存 (4)
- Storm (1)
- MongoDB (9)
- Spring boot (16)
- log4j (2)
- maven (3)
- nginx (5)
- Tomcat (2)
- Eclipse (4)
- Swagger (2)
- Netty (5)
- Dubbo (1)
- Docker (7)
- Hadoop (12)
- OAuth (1)
- webSocket (4)
- 服务器性能 (7)
- Session共享 (1)
- tieye修改 (1)
- 工作 (1)
- 有用的语录 (0)
- https (2)
- common (5)
- 产品开发管理 (1)
- CDN 工作原理 (1)
- APNS、GCM (1)
- 架构图 (3)
- 功能实现分析 (1)
- JMX (1)
- 服务器相关操作命令 (1)
- img02 (0)
- 服务器环境搭建 (9)
- goodMenuBook (1)
- CEInstantPot (0)
- 有用数据 (1)
- 百度地图WEB API (2)
- 正则表达式 (1)
- 样式例子 (2)
- staticRecipePressureCooker.zip (1)
- jCanvas (1)
- 网站攻击方法原理 (1)
- 架构设计 (3)
- 物联网相关 (3)
- 研发管理 (7)
- 技术需求点 (1)
- 计划 (1)
- spring cloud (11)
- 服务器开发的一些实用工具和方法 (1)
- 每天学到的技术点 (4)
- Guava (1)
- ERP 技术注意要点 (2)
- 微信小程序 (1)
- FineRepor (1)
- 收藏夹 (1)
- temp (5)
- 服务架构 (4)
- 任职资格方案 (0)
- osno_test (1)
- jquery相关 (3)
- mybatis (4)
- ueditor (1)
- VueJS (7)
- python (10)
- Spring EL (1)
- shiro (1)
- 前端开发原理与使用 (7)
- YARN (1)
- Spark (1)
- Hbase (2)
- Pig (2)
- 机器学习 (30)
- matplotlib (1)
- OpenCV (17)
- Hystrix (1)
- 公司 (1)
- miniui (4)
- 前端功能实现 (3)
- 前端插件 (1)
- 钉钉开发 (2)
- Jenkins (1)
- elasticSearch使用 (2)
- 技术规范 (4)
- 技术实现原理 (0)
最新评论
//工具安装前的准备与相关简单用到的命令
node -v
npm -v
npm init 初始化一个空项目是一个好的习惯,生成一个package.json
npm i 是 npm install 的简写,建议使用 npm i
npm i express --save/npm i express -S (安装 express,同时将 "express": "^4.14.0" 写入 dependencies )
npm i express --save-dev/npm i express -D (安装 express,同时将 "express": "^4.14.0" 写入 devDependencies )
npm start 等价于 npm run start
npm test 等价于 npm run test
NODE_ENV=test node app
通过以上命令启动程序,指定当前环境变量 NODE_ENV 的值为 test,那么在 app.js 中可通过 process.env 来获取环境变量:
console.log(process.env.NODE_ENV) //test
//前端格式化工具与检测工具选择与使用
HTML:选择htmlHint进行检测,选择prettier进行格式化
CSS:选择stylelint进行检测,stylelint-order进行CSS属性排序插件排序,选择prettier进行格式化
JS:选择ESLint进行检测,选择prettier进行格式化
想检测Html中的JavaScript,加入
npm i eslint-plugin-html -D
prettier安装使用:
https://www.cnblogs.com/guwufeiyang/p/12886333.html
工具建议全局安装
全局安装
npm install --global prettier
局部安装
npm install --save-dev --save-exact prettier
yarn add prettier --dev --exact
运行配置文件,建议使用js格式(JSON,JS,YAML)
.prettierrc.js (例子)
module.exports = {
printWidth: 120, //编辑器每行的长度,默认80;
semi: true, //是否使用分号,默认true,使用分号;
singleQuote: true, //是否使用单引号,默认为false,不适用单引号,使用双引号;
bracketSpacing: true, //对象括号中的空格,默认true;
tabWidth: 4, //制表符tab的宽度,默认值是2;
useTabs: true, //代码缩进是否用制表符tab,默认false;
TrailingCooma: 'all', //末尾逗号,none 末尾没有逗号,es5 es5有效的地方保留,all 在可能的地方都加上逗号;
jsxBracketSameLine: false, //jsx标签闭合位置 默认false,
};
更多自定义配置:https://prettier.io/docs/en/options.html?spm=a2c4e.11153940.blogcont422690.11.5d0b5721zz3ckz
执行格式化
prettier --config 配置位置 --write 需要格式化的文件
基础用法
prettier --config ./.prettierrc --write ./index.js
扩展用法(自定义文件配置以及格式化vue文件)
prettier --config ./pre.js --write ./index.vue
webstrom可以在file watcher中进行prettier的监听,做到保存时就进行格式化
htmlhint安装使用:
https://www.cnblogs.com/imwtr/p/9189414.html
npm i -g htmlhint
webstrom安装htmlhint插件;
因此插件比较特殊,在windows下,bin中请使用 node执行程序的绝对路径 全局 htmlhint的绝对路径
bin: D:\Program Files\nodejs\node.exe C:\Users\e470\AppData\Roaming\npm\node_modules\htmlhint\bin\htmlhint
path: .htmlhintrc
.htmlhintrc(只支持JSON方式进行配置)
{
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"attr-value-not-empty": false,
"attr-no-duplication": false,
"doctype-first": true,
"tag-pair": true,
"tag-self-close": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"title-require": true,
"alt-require": true,
"doctype-html5": true,
"id-class-value": "hump",
"style-disabled": false,
"inline-style-disabled": false,
"inline-script-disabled": false,
"space-tab-mixed-disabled": "tab",
"id-class-ad-disabled": true,
"href-abs-or-rel": false,
}
对应说明:
标签名必须小写
属性名必须小写
属性值必须放在双引号中
属性值一定不可为空
属性值一定不可重复
Doctype必须是 HTML 文档的第一行
标签必须成对
标签必须自封闭
特殊字符必须
ID 属性必须唯一
src 属性一定不可为空
title 属性必须出现在标签中
img 标签必须包含 alt 属性
Doctype 必须是 HTML5
ID 和 Class 的命名规则必须统一
不该使用样式标签
不该使用行内样式
不该使用行内脚本
空格和制表符一定不可混合在行前
ID 和 Class 一定不可使用广告关键词
href 必须是绝对路径或者相对路径
属性值一定不可使用不安全字符
script 标签不该使用在头部
————————————————
https://blog.csdn.net/weixin_40073115/article/details/103819884
更详细说明:
https://blog.csdn.net/LuckXinXin/article/details/105421681
简单使用:
htmlhint testt/tdTest.html
stylelint安装使用:
一个强大的、现代化的 CSS 检测工具
https://www.cnblogs.com/jiaoshou/p/11284204.html
https://blog.csdn.net/maimiho/article/details/110226793
安装:
npm i stylelint stylelint-config-standard stylelint-config-prettier stylelint-order -D
yarn add stylelint stylelint-config-standard stylelint-config-prettier stylelint-order --dev
其中,stylelint是运行工具,stylelint-config-standard是stylelint的推荐配置,
stylelint-order是CSS属性排序插件(先写定位,再写盒模型,再写内容区样式,最后写 CSS3 相关属性)。
① stylelint
② stylelint-config-standard:一些常见的css书写规范
③ stylelint-config-prettier:关闭所有不必要的或者有可能与Prettier冲突的规则
④ stylelint-order:提供给css属性排序的功能
⑤ stylelint-config-rational-order:一套常见的css书写顺序
⑥ prettier: 格式化
webstrom中配置stylelint运行环境
https://www.cnblogs.com/imwtr/p/9189414.html
stylelint --fix 用于运行stylelint-order排序
stylelint --fix testt/tdTest.html //不能用“\”
.stylelintrc.js(配置文件)
module.exports = {
extends: [
"stylelint-config-standard",
"stylelint-config-recess-order",
"stylelint-config-prettier",
],
plugins: ["stylelint-scss", "stylelint-order"],
rules: {
"at-rule-no-unknown": [
true,
{
ignoreAtRules: [
"extend",
"at-root",
"debug",
"warn",
"error",
"if",
"else",
"for",
"each",
"while",
"mixin",
"include",
"content",
"return",
"function",
],
},
],ignoreatrulesignoreatrulesignoreatrulesignoreatrulesignoreatrulesignoreAtRules
},
};
webStrom可以在file Watcher中进行prettier的监听,做到保存时就进行格式化(感觉会要多种文件类型要监听,不太好用,还是手动触发好点)
stylelint --fix testt/tdTest.html //不能用“\”
配置参数
D:\webTest\eslitTest\node_modules\.bin\stylelint.cmd
$/FileRelativePath$ --fix
$/FileRelativePath$
配置stylelint-order的快捷方式:
webStrom中在tool中加入这个外部工具,方便你在保存时就进行一次排序
快捷方式配置参数
D:\webTest\eslitTest\node_modules\.bin\stylelint.cmd
$FileName$ --fix
$FileDir$
webStrom中在file watcher 中加入这个外部工具,方便你在保存时就进行一次排序
ESLint安装使用:
https://www.cnblogs.com/lsgxeva/p/7994474.html
安装
npm i -g eslint babel-eslint eslint-config-alloy eslint-plugin-html
npm install eslint --save-dev
yarn add eslint babel-eslint eslint-config-alloy eslint-plugin-html --dev
eslint --init //设置完成后我们会得到一份文件名为 .eslintrc.js 的配置文件
.eslintrc.js
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
},
env: {
browser: true,
//; node: true,;
es6: true,;
jquery: true,
},
plugins: ['html'],
// extends: 'standard',
extends: ['eslint:recommended'],
rules: {
'vue/max-attributes-per-line': [
0,
{
singleline: 10,;singleline;singleline;singleline;singleline;singleline;singleline
multiline: {;;;;;;
max: 1,;;;;;;
allowFirstLine: true,
},
},
];,
'vue/singleline-html-element-content-newline': 'off';,
'vue/multiline-html-element-content-newline': 'off';,
'vue/name-property-casing': [0, 'PascalCase'];,
'vue/no-v-html': 'off';,
'accessor-pairs': 2,
'arrow-spacing': [
2,
{
before: true,
after: true,
},
],
'block-spacing': [2, 'always'],
'brace-style': [
2,
'1tbs',
{
allowsingleline: true,
},
],
camelcase: [
2,
{
properties: 'always',
},
],
'comma-dangle': [0, 'never'], //对象字面量项尾不能有逗号
'comma-spacing': [
2,
{
before: false,
after: true,
},
],
'comma-style': [2, 'last'],
'constructor-super': 2,
curly: [2, 'multi-line'],
'dot-location': [2, 'property'],
'eol-last': 2,
eqeqeq: ['error', 'always'],
'generator-star-spacing': [
2,
{
before: true,
after: true,
},
],
'handle-callback-err': [2, '^(err|error)$'],
indent: [
2,
'tab',
{
switchcase: 1,
},
],
'jsx-quotes': [2, 'prefer-single'],
'key-spacing': [
2,
{
beforecolon: false,
aftercolon: true,
},
],
'keyword-spacing': [
2,
{
before: true,
after: true,
},
],
'new-cap': [
2,
{
newiscap: true,
capisnew: false,
},
],
'new-parens': 2,
'no-array-constructor': 2,
'no-caller': 2,
'no-console': 'off',
'no-class-assign': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-control-regex': 0,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-constant-condition': 2,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-eval': 2,
'no-ex-assign': 2,
'no-extend-native': 2,
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-parens': [2, 'functions'],
'no-fallthrough': 2,
'no-floating-decimal': 2,
'no-func-assign': 2,
'no-implied-eval': 2,
'no-inner-declarations': [2, 'functions'],
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-iterator': 2,
'no-label-var': 2,
'no-labels': [
2,
{
allowloop: false,
allowswitch: false,
},
],
'no-lone-blocks': 2,
'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2,
'no-multi-str': 2,
'no-multiple-empty-lines': [
2,
{
max: 10,
},
],
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new-object': 2,
'no-new-require': 2,
'no-new-symbol': 2,
'no-new-wrappers': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-octal-escape': 2,
'no-path-concat': 2,
'no-proto': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2,
'no-self-compare': 2,
'no-sequences': 2,
'no-shadow-restricted-names': 2,
'no-spaced-func': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 2,
'no-trailing-spaces': 2,
'no-undef': 0,
'no-undef-init': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unneeded-ternary': [
2,
{
defaultassignment: false,
},
],
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unused-vars': [
1,
{
vars: 'local',
args: 'none',
},
],
'no-useless-call': 0,
'no-useless-computed-key': 2,
'no-useless-constructor': 2,
'no-useless-escape': 0,
'no-whitespace-before-property': 2,
'no-with': 2,
'one-var': [
2,
{
initialized: 'never',
},
],
'operator-linebreak': [
2,
'after',
{
overrides: {
'?': 'before',
':': 'before',
},
},
],
'padded-blocks': [2, 'never'],
quotes: [
2,
'single',
{
avoidescape: true,
allowtemplateliterals: true,
},
],
// 'quotes': [2, 'double', {
// // 'avoidEscape': true,
// // 'allowTemplateLiterals': true
// // }],
semi: [2, 'always'],
'semi-spacing': [
2,
{
before: false,
after: true,
},
],
'space-before-blocks': [2, 'always'],
'space-before-function-paren': [0, 'never'],
'space-in-parens': [2, 'never'],
'space-infix-ops': 2,
'space-unary-ops': [
2,
{
words: true,
nonwords: false,
},
],
'spaced-comment': [
0,
'always',
{
markers: ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','],
},
],
'template-curly-spacing': [2, 'never'],
'use-isnan': 2,
'valid-typeof': 2,
'wrap-iife': [2, 'any'],
'yield-star-spacing': [2, 'both'],
yoda: [2, 'never'],
'prefer-const': 2,
'array-bracket-spacing': [2, 'never'
},
};
eslint配置环境(上面内容分析)
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"jquery"
}
env 属性来指定要启用的环境,将其设置为 true,以保证在进行代码检测时不会把这些环境预定义的全局变量识别成未定义的变量而报错:
设置语言选项
默认情况下,eslint 支持 ecmascript 5 语法,如果你想启用对 ecmascript 其它版本和 jsx 等的支持,eslint 允许你使用 parseroptions 属性进行指定想要支持的 javascript 语言选项,不过你可能需要自行安装 eslint-plugin-react 等插件。
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
}
配置规则
在上文的配置文件中, "extends": "eslint:recommended" 选项表示启用推荐规则,在推荐规则的基础上我们还可以根据需要使用 rules 新增自定义规则,每个规则的第一个值都是代表该规则检测后显示的错误级别:
"off" 或 0 - 关闭规则
"warn" 或 1 - 将规则视为一个警告
"error" 或 2 - 将规则视为一个错误
rules: {
"规则名": [规则值, 规则配置]
}
你可以在任何文件或目录上运行eslint如下命令进行检测规则
eslint yourfile.js
想检测html中的javascript
npm i eslint-plugin-html -d
webstrom可以在file watcher中进行prettier的监听,做到保存时就进行格式化
$ProjectFileDir$\node_modules\.bin\prettier
--write $FilePathRelativeToProjectRoot$
eslint配置
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
},
env: {
browser: true,
// node: true,
es6: true,
jquery: true,
},
plugins: ['html'],
// extends: 'standard',
extends: ['eslint:recommended'],
rules: {
'vue/max-attributes-per-line': [
0,
{
singleline: 10,
multiline: {
max: 1,
allowFirstLine: true,
},
},
],
'vue/singleline-html-element-content-newline': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/name-property-casing': [0, 'PascalCase'],
'vue/no-v-html': 'off',
'accessor-pairs': 2,
'arrow-spacing': [
2,
{
before: true,
after: true,
},
],
'block-spacing': [2, 'always'],
'brace-style': [
2,
'1tbs',
{
allowSingleLine: true,
},
],
camelcase: [
2,
{
properties: 'always',
},
],
'comma-dangle': [0, 'never'], //对象字面量项尾不能有逗号
'comma-spacing': [
2,
{
before: false,
after: true,
},
],
'comma-style': [2, 'last'],
'constructor-super': 2,
curly: [2, 'multi-line'],
'dot-location': [2, 'property'],
'eol-last': 2,
eqeqeq: ['error', 'always'],
'generator-star-spacing': [
2,
{
before: true,
after: true,
},
],
'handle-callback-err': [2, '^(err|error)$'],
indent: [
2,
'tab',
{
SwitchCase: 1,
},
],
'jsx-quotes': [2, 'prefer-single'],
'key-spacing': [
2,
{
beforeColon: false,
afterColon: true,
},
],
'keyword-spacing': [
2,
{
before: true,
after: true,
},
],
'new-cap': [
2,
{
newIsCap: true,
capIsNew: false,
},
],
'new-parens': 2,
'no-array-constructor': 2,
'no-caller': 2,
'no-console': 'off',
'no-class-assign': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-control-regex': 0,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-constant-condition': 1,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-eval': 2,
'no-ex-assign': 2,
'no-extend-native': 2,
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-parens': [2, 'functions'],
'no-fallthrough': 2,
'no-floating-decimal': 2,
'no-func-assign': 2,
'no-implied-eval': 1,
'no-inner-declarations': [2, 'functions'],
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-iterator': 2,
'no-label-var': 2,
'no-labels': [
2,
{
allowLoop: false,
allowSwitch: false,
},
],
'no-lone-blocks': 2,
'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2,
'no-multi-str': 2,
'no-multiple-empty-lines': [
2,
{
max: 10,
},
],
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new-object': 2,
'no-new-require': 2,
'no-new-symbol': 2,
'no-new-wrappers': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-octal-escape': 2,
'no-path-concat': 2,
'no-proto': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2,
'no-self-compare': 2,
'no-sequences': 2,
'no-shadow-restricted-names': 2,
'no-spaced-func': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 0,
'no-trailing-spaces': 2,
'no-undef': 0,
'no-undef-init': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unneeded-ternary': [
2,
{
defaultAssignment: false,
},
],
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unused-vars': [
1,
{
vars: 'local',
args: 'none',
},
],
'no-useless-call': 0,
'no-useless-computed-key': 2,
'no-useless-constructor': 2,
'no-useless-escape': 0,
'no-whitespace-before-property': 2,
'no-with': 2,
'one-var': [
2,
{
initialized: 'never',
},
],
'operator-linebreak': [
2,
'after',
{
overrides: {
'?': 'before',
':': 'before',
},
},
],
'padded-blocks': [2, 'never'],
quotes: [
2,
'single',
{
avoidEscape: true,
allowTemplateLiterals: true,
},
],
// 'quotes': [2, 'double', {
// // 'avoidEscape': true,
// // 'allowTemplateLiterals': true
// // }],
semi: [2, 'always'],
'semi-spacing': [
2,
{
before: false,
after: true,
},
],
'space-before-blocks': [2, 'always'],
'space-before-function-paren': [0, 'never'],
'space-in-parens': [2, 'never'],
'space-infix-ops': 2,
'space-unary-ops': [
2,
{
words: true,
nonwords: false,
},
],
'spaced-comment': [
0,
'always',
{
markers: ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','],
},
],
'template-curly-spacing': [2, 'never'],
'use-isnan': 2,
'valid-typeof': 2,
'wrap-iife': [2, 'any'],
'yield-star-spacing': [2, 'both'],
yoda: [2, 'never'],
'prefer-const': 2,
'array-bracket-spacing': [2, 'never'],
},
};
node -v
npm -v
npm init 初始化一个空项目是一个好的习惯,生成一个package.json
npm i 是 npm install 的简写,建议使用 npm i
npm i express --save/npm i express -S (安装 express,同时将 "express": "^4.14.0" 写入 dependencies )
npm i express --save-dev/npm i express -D (安装 express,同时将 "express": "^4.14.0" 写入 devDependencies )
npm start 等价于 npm run start
npm test 等价于 npm run test
NODE_ENV=test node app
通过以上命令启动程序,指定当前环境变量 NODE_ENV 的值为 test,那么在 app.js 中可通过 process.env 来获取环境变量:
console.log(process.env.NODE_ENV) //test
//前端格式化工具与检测工具选择与使用
HTML:选择htmlHint进行检测,选择prettier进行格式化
CSS:选择stylelint进行检测,stylelint-order进行CSS属性排序插件排序,选择prettier进行格式化
JS:选择ESLint进行检测,选择prettier进行格式化
想检测Html中的JavaScript,加入
npm i eslint-plugin-html -D
prettier安装使用:
https://www.cnblogs.com/guwufeiyang/p/12886333.html
工具建议全局安装
全局安装
npm install --global prettier
局部安装
npm install --save-dev --save-exact prettier
yarn add prettier --dev --exact
运行配置文件,建议使用js格式(JSON,JS,YAML)
.prettierrc.js (例子)
module.exports = {
printWidth: 120, //编辑器每行的长度,默认80;
semi: true, //是否使用分号,默认true,使用分号;
singleQuote: true, //是否使用单引号,默认为false,不适用单引号,使用双引号;
bracketSpacing: true, //对象括号中的空格,默认true;
tabWidth: 4, //制表符tab的宽度,默认值是2;
useTabs: true, //代码缩进是否用制表符tab,默认false;
TrailingCooma: 'all', //末尾逗号,none 末尾没有逗号,es5 es5有效的地方保留,all 在可能的地方都加上逗号;
jsxBracketSameLine: false, //jsx标签闭合位置 默认false,
};
更多自定义配置:https://prettier.io/docs/en/options.html?spm=a2c4e.11153940.blogcont422690.11.5d0b5721zz3ckz
执行格式化
prettier --config 配置位置 --write 需要格式化的文件
基础用法
prettier --config ./.prettierrc --write ./index.js
扩展用法(自定义文件配置以及格式化vue文件)
prettier --config ./pre.js --write ./index.vue
webstrom可以在file watcher中进行prettier的监听,做到保存时就进行格式化
htmlhint安装使用:
https://www.cnblogs.com/imwtr/p/9189414.html
npm i -g htmlhint
webstrom安装htmlhint插件;
因此插件比较特殊,在windows下,bin中请使用 node执行程序的绝对路径 全局 htmlhint的绝对路径
bin: D:\Program Files\nodejs\node.exe C:\Users\e470\AppData\Roaming\npm\node_modules\htmlhint\bin\htmlhint
path: .htmlhintrc
.htmlhintrc(只支持JSON方式进行配置)
{
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"attr-value-not-empty": false,
"attr-no-duplication": false,
"doctype-first": true,
"tag-pair": true,
"tag-self-close": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"title-require": true,
"alt-require": true,
"doctype-html5": true,
"id-class-value": "hump",
"style-disabled": false,
"inline-style-disabled": false,
"inline-script-disabled": false,
"space-tab-mixed-disabled": "tab",
"id-class-ad-disabled": true,
"href-abs-or-rel": false,
}
对应说明:
标签名必须小写
属性名必须小写
属性值必须放在双引号中
属性值一定不可为空
属性值一定不可重复
Doctype必须是 HTML 文档的第一行
标签必须成对
标签必须自封闭
特殊字符必须
ID 属性必须唯一
src 属性一定不可为空
title 属性必须出现在标签中
img 标签必须包含 alt 属性
Doctype 必须是 HTML5
ID 和 Class 的命名规则必须统一
不该使用样式标签
不该使用行内样式
不该使用行内脚本
空格和制表符一定不可混合在行前
ID 和 Class 一定不可使用广告关键词
href 必须是绝对路径或者相对路径
属性值一定不可使用不安全字符
script 标签不该使用在头部
————————————————
https://blog.csdn.net/weixin_40073115/article/details/103819884
更详细说明:
https://blog.csdn.net/LuckXinXin/article/details/105421681
简单使用:
htmlhint testt/tdTest.html
stylelint安装使用:
一个强大的、现代化的 CSS 检测工具
https://www.cnblogs.com/jiaoshou/p/11284204.html
https://blog.csdn.net/maimiho/article/details/110226793
安装:
npm i stylelint stylelint-config-standard stylelint-config-prettier stylelint-order -D
yarn add stylelint stylelint-config-standard stylelint-config-prettier stylelint-order --dev
其中,stylelint是运行工具,stylelint-config-standard是stylelint的推荐配置,
stylelint-order是CSS属性排序插件(先写定位,再写盒模型,再写内容区样式,最后写 CSS3 相关属性)。
① stylelint
② stylelint-config-standard:一些常见的css书写规范
③ stylelint-config-prettier:关闭所有不必要的或者有可能与Prettier冲突的规则
④ stylelint-order:提供给css属性排序的功能
⑤ stylelint-config-rational-order:一套常见的css书写顺序
⑥ prettier: 格式化
webstrom中配置stylelint运行环境
https://www.cnblogs.com/imwtr/p/9189414.html
stylelint --fix 用于运行stylelint-order排序
stylelint --fix testt/tdTest.html //不能用“\”
.stylelintrc.js(配置文件)
module.exports = {
extends: [
"stylelint-config-standard",
"stylelint-config-recess-order",
"stylelint-config-prettier",
],
plugins: ["stylelint-scss", "stylelint-order"],
rules: {
"at-rule-no-unknown": [
true,
{
ignoreAtRules: [
"extend",
"at-root",
"debug",
"warn",
"error",
"if",
"else",
"for",
"each",
"while",
"mixin",
"include",
"content",
"return",
"function",
],
},
],ignoreatrulesignoreatrulesignoreatrulesignoreatrulesignoreatrulesignoreAtRules
},
};
webStrom可以在file Watcher中进行prettier的监听,做到保存时就进行格式化(感觉会要多种文件类型要监听,不太好用,还是手动触发好点)
stylelint --fix testt/tdTest.html //不能用“\”
配置参数
D:\webTest\eslitTest\node_modules\.bin\stylelint.cmd
$/FileRelativePath$ --fix
$/FileRelativePath$
配置stylelint-order的快捷方式:
webStrom中在tool中加入这个外部工具,方便你在保存时就进行一次排序
快捷方式配置参数
D:\webTest\eslitTest\node_modules\.bin\stylelint.cmd
$FileName$ --fix
$FileDir$
webStrom中在file watcher 中加入这个外部工具,方便你在保存时就进行一次排序
ESLint安装使用:
https://www.cnblogs.com/lsgxeva/p/7994474.html
安装
npm i -g eslint babel-eslint eslint-config-alloy eslint-plugin-html
npm install eslint --save-dev
yarn add eslint babel-eslint eslint-config-alloy eslint-plugin-html --dev
eslint --init //设置完成后我们会得到一份文件名为 .eslintrc.js 的配置文件
.eslintrc.js
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
},
env: {
browser: true,
//; node: true,;
es6: true,;
jquery: true,
},
plugins: ['html'],
// extends: 'standard',
extends: ['eslint:recommended'],
rules: {
'vue/max-attributes-per-line': [
0,
{
singleline: 10,;singleline;singleline;singleline;singleline;singleline;singleline
multiline: {;;;;;;
max: 1,;;;;;;
allowFirstLine: true,
},
},
];,
'vue/singleline-html-element-content-newline': 'off';,
'vue/multiline-html-element-content-newline': 'off';,
'vue/name-property-casing': [0, 'PascalCase'];,
'vue/no-v-html': 'off';,
'accessor-pairs': 2,
'arrow-spacing': [
2,
{
before: true,
after: true,
},
],
'block-spacing': [2, 'always'],
'brace-style': [
2,
'1tbs',
{
allowsingleline: true,
},
],
camelcase: [
2,
{
properties: 'always',
},
],
'comma-dangle': [0, 'never'], //对象字面量项尾不能有逗号
'comma-spacing': [
2,
{
before: false,
after: true,
},
],
'comma-style': [2, 'last'],
'constructor-super': 2,
curly: [2, 'multi-line'],
'dot-location': [2, 'property'],
'eol-last': 2,
eqeqeq: ['error', 'always'],
'generator-star-spacing': [
2,
{
before: true,
after: true,
},
],
'handle-callback-err': [2, '^(err|error)$'],
indent: [
2,
'tab',
{
switchcase: 1,
},
],
'jsx-quotes': [2, 'prefer-single'],
'key-spacing': [
2,
{
beforecolon: false,
aftercolon: true,
},
],
'keyword-spacing': [
2,
{
before: true,
after: true,
},
],
'new-cap': [
2,
{
newiscap: true,
capisnew: false,
},
],
'new-parens': 2,
'no-array-constructor': 2,
'no-caller': 2,
'no-console': 'off',
'no-class-assign': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-control-regex': 0,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-constant-condition': 2,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-eval': 2,
'no-ex-assign': 2,
'no-extend-native': 2,
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-parens': [2, 'functions'],
'no-fallthrough': 2,
'no-floating-decimal': 2,
'no-func-assign': 2,
'no-implied-eval': 2,
'no-inner-declarations': [2, 'functions'],
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-iterator': 2,
'no-label-var': 2,
'no-labels': [
2,
{
allowloop: false,
allowswitch: false,
},
],
'no-lone-blocks': 2,
'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2,
'no-multi-str': 2,
'no-multiple-empty-lines': [
2,
{
max: 10,
},
],
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new-object': 2,
'no-new-require': 2,
'no-new-symbol': 2,
'no-new-wrappers': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-octal-escape': 2,
'no-path-concat': 2,
'no-proto': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2,
'no-self-compare': 2,
'no-sequences': 2,
'no-shadow-restricted-names': 2,
'no-spaced-func': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 2,
'no-trailing-spaces': 2,
'no-undef': 0,
'no-undef-init': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unneeded-ternary': [
2,
{
defaultassignment: false,
},
],
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unused-vars': [
1,
{
vars: 'local',
args: 'none',
},
],
'no-useless-call': 0,
'no-useless-computed-key': 2,
'no-useless-constructor': 2,
'no-useless-escape': 0,
'no-whitespace-before-property': 2,
'no-with': 2,
'one-var': [
2,
{
initialized: 'never',
},
],
'operator-linebreak': [
2,
'after',
{
overrides: {
'?': 'before',
':': 'before',
},
},
],
'padded-blocks': [2, 'never'],
quotes: [
2,
'single',
{
avoidescape: true,
allowtemplateliterals: true,
},
],
// 'quotes': [2, 'double', {
// // 'avoidEscape': true,
// // 'allowTemplateLiterals': true
// // }],
semi: [2, 'always'],
'semi-spacing': [
2,
{
before: false,
after: true,
},
],
'space-before-blocks': [2, 'always'],
'space-before-function-paren': [0, 'never'],
'space-in-parens': [2, 'never'],
'space-infix-ops': 2,
'space-unary-ops': [
2,
{
words: true,
nonwords: false,
},
],
'spaced-comment': [
0,
'always',
{
markers: ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','],
},
],
'template-curly-spacing': [2, 'never'],
'use-isnan': 2,
'valid-typeof': 2,
'wrap-iife': [2, 'any'],
'yield-star-spacing': [2, 'both'],
yoda: [2, 'never'],
'prefer-const': 2,
'array-bracket-spacing': [2, 'never'
},
};
eslint配置环境(上面内容分析)
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"jquery"
}
env 属性来指定要启用的环境,将其设置为 true,以保证在进行代码检测时不会把这些环境预定义的全局变量识别成未定义的变量而报错:
设置语言选项
默认情况下,eslint 支持 ecmascript 5 语法,如果你想启用对 ecmascript 其它版本和 jsx 等的支持,eslint 允许你使用 parseroptions 属性进行指定想要支持的 javascript 语言选项,不过你可能需要自行安装 eslint-plugin-react 等插件。
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
}
配置规则
在上文的配置文件中, "extends": "eslint:recommended" 选项表示启用推荐规则,在推荐规则的基础上我们还可以根据需要使用 rules 新增自定义规则,每个规则的第一个值都是代表该规则检测后显示的错误级别:
"off" 或 0 - 关闭规则
"warn" 或 1 - 将规则视为一个警告
"error" 或 2 - 将规则视为一个错误
rules: {
"规则名": [规则值, 规则配置]
}
你可以在任何文件或目录上运行eslint如下命令进行检测规则
eslint yourfile.js
想检测html中的javascript
npm i eslint-plugin-html -d
webstrom可以在file watcher中进行prettier的监听,做到保存时就进行格式化
$ProjectFileDir$\node_modules\.bin\prettier
--write $FilePathRelativeToProjectRoot$
eslint配置
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
},
env: {
browser: true,
// node: true,
es6: true,
jquery: true,
},
plugins: ['html'],
// extends: 'standard',
extends: ['eslint:recommended'],
rules: {
'vue/max-attributes-per-line': [
0,
{
singleline: 10,
multiline: {
max: 1,
allowFirstLine: true,
},
},
],
'vue/singleline-html-element-content-newline': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/name-property-casing': [0, 'PascalCase'],
'vue/no-v-html': 'off',
'accessor-pairs': 2,
'arrow-spacing': [
2,
{
before: true,
after: true,
},
],
'block-spacing': [2, 'always'],
'brace-style': [
2,
'1tbs',
{
allowSingleLine: true,
},
],
camelcase: [
2,
{
properties: 'always',
},
],
'comma-dangle': [0, 'never'], //对象字面量项尾不能有逗号
'comma-spacing': [
2,
{
before: false,
after: true,
},
],
'comma-style': [2, 'last'],
'constructor-super': 2,
curly: [2, 'multi-line'],
'dot-location': [2, 'property'],
'eol-last': 2,
eqeqeq: ['error', 'always'],
'generator-star-spacing': [
2,
{
before: true,
after: true,
},
],
'handle-callback-err': [2, '^(err|error)$'],
indent: [
2,
'tab',
{
SwitchCase: 1,
},
],
'jsx-quotes': [2, 'prefer-single'],
'key-spacing': [
2,
{
beforeColon: false,
afterColon: true,
},
],
'keyword-spacing': [
2,
{
before: true,
after: true,
},
],
'new-cap': [
2,
{
newIsCap: true,
capIsNew: false,
},
],
'new-parens': 2,
'no-array-constructor': 2,
'no-caller': 2,
'no-console': 'off',
'no-class-assign': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-control-regex': 0,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-constant-condition': 1,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-eval': 2,
'no-ex-assign': 2,
'no-extend-native': 2,
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-parens': [2, 'functions'],
'no-fallthrough': 2,
'no-floating-decimal': 2,
'no-func-assign': 2,
'no-implied-eval': 1,
'no-inner-declarations': [2, 'functions'],
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-iterator': 2,
'no-label-var': 2,
'no-labels': [
2,
{
allowLoop: false,
allowSwitch: false,
},
],
'no-lone-blocks': 2,
'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2,
'no-multi-str': 2,
'no-multiple-empty-lines': [
2,
{
max: 10,
},
],
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new-object': 2,
'no-new-require': 2,
'no-new-symbol': 2,
'no-new-wrappers': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-octal-escape': 2,
'no-path-concat': 2,
'no-proto': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2,
'no-self-compare': 2,
'no-sequences': 2,
'no-shadow-restricted-names': 2,
'no-spaced-func': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 0,
'no-trailing-spaces': 2,
'no-undef': 0,
'no-undef-init': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unneeded-ternary': [
2,
{
defaultAssignment: false,
},
],
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unused-vars': [
1,
{
vars: 'local',
args: 'none',
},
],
'no-useless-call': 0,
'no-useless-computed-key': 2,
'no-useless-constructor': 2,
'no-useless-escape': 0,
'no-whitespace-before-property': 2,
'no-with': 2,
'one-var': [
2,
{
initialized: 'never',
},
],
'operator-linebreak': [
2,
'after',
{
overrides: {
'?': 'before',
':': 'before',
},
},
],
'padded-blocks': [2, 'never'],
quotes: [
2,
'single',
{
avoidEscape: true,
allowTemplateLiterals: true,
},
],
// 'quotes': [2, 'double', {
// // 'avoidEscape': true,
// // 'allowTemplateLiterals': true
// // }],
semi: [2, 'always'],
'semi-spacing': [
2,
{
before: false,
after: true,
},
],
'space-before-blocks': [2, 'always'],
'space-before-function-paren': [0, 'never'],
'space-in-parens': [2, 'never'],
'space-infix-ops': 2,
'space-unary-ops': [
2,
{
words: true,
nonwords: false,
},
],
'spaced-comment': [
0,
'always',
{
markers: ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','],
},
],
'template-curly-spacing': [2, 'never'],
'use-isnan': 2,
'valid-typeof': 2,
'wrap-iife': [2, 'any'],
'yield-star-spacing': [2, 'both'],
yoda: [2, 'never'],
'prefer-const': 2,
'array-bracket-spacing': [2, 'never'],
},
};
发表评论
-
定时调用函数功能实现
2021-06-11 10:26 1074<html> <head> & ... -
uniApiJs
2021-06-08 18:04 0//获取当前的地理位置、速度 function getLoca ... -
百度人脸识别
2021-05-21 16:11 331package com.gaojinsoft.htwy.y20 ... -
点击DIV触发上传文件的方法
2021-05-20 14:11 1127<div Style="float:left ... -
indexedDb TEST
2021-03-24 08:36 473<!DOCTYPE html> <html& ... -
defineProperty Array push 监听
2020-10-31 15:16 437<!DOCTYPE html> <html ... -
weuiJsLayer.js
2020-07-24 09:56 242var weuiJsAlterMap = {}; f ... -
dataViewCommonJs
2020-05-09 17:00 329// var _elementIdToDataMap={} ... -
editorconfig配置
2020-03-28 20:36 420# https://editorconfig.org root ... -
commonJs
2020-03-26 21:25 340//本包使用需要先引入jquery //获取数组中的重复元素 ... -
setFormData
2019-12-20 22:30 0function setFormData(selector,d ... -
jQuery Validate 校验
2019-09-25 21:16 290https://www.runoob.com/jquery/j ... -
高德地图获取地址
2019-09-11 14:42 463高德帐号 135704744 <!doctype ... -
附件下载和导出
2019-07-19 16:55 567//post下载导出附件 function export ... -
miniUITest
2019-07-12 15:35 315miniUITest -
from转JSON的Obj 、js空判断、 js数字判断
2019-07-04 22:54 452miniUI总界面 from转JSON的Obj js空判断 j ... -
前端实现从剪贴板中获取数据
2019-05-16 14:01 1397//绑定在了body上,也可以绑定在其他可用元素行,但是不是所 ... -
js prototype原理与使用
2018-08-14 15:59 730js prototype原理与使用 prototype 使您 ... -
JS过滤树数据
2018-07-02 16:45 987<!DOCTYPE html> <html ... -
background-position
2017-05-15 19:30 481<html> <head> ...
相关推荐
Json页面美化(页面自动检测并格式化,强制开启) 二维码生成器(支持当前页面生成QrCode) 页面取色工具(滑动鼠标随意取色) Js正则表达式(正则测试、常用正则列表) 时间(戳)转换(Unix戳与本地时间的互转) ...
FeHelper前端助手,包含一些前端实用的工具,如字符串编解码、代码美化、JSON格式化查看、二维码生成器、编码规范检测、栅格规范检测、网页性能检测、页面取色等web前端开发的常见功能。
1)ESlint:javascript代码检测工具,可以配置每次保存时格式化js,但每次保存只格式化一点点,你得连续按住Ctrl+S好几次,才格式化好,自行体会~~ 2)vetur:可以格式化html、标准css(有分号 、大括号的那种)、...
其实所有C系的代码,都可以通过Javascript代码美化工具进行格式化查看 代码压缩 包括Web前端Javascript代码压缩、CSS代码压缩、HTML代码压缩 JSON接口自动格式化查看 当你访问的接口(打开的页面)返回的是一个JSON...
JS常用工具函数(压缩包中含有MD文件可自行查看)--包含:通用格式化时间、字符串验证-验证邮箱、手机号、电话号码、url地址、严格校验身份证号码,判断数据类型-是否是字符串、数字、Boolean、函数、对象、数组...
WEB前端助手:FeHelper,浏览器插件,包含一些前端实用的工具,如包括JSON格式化、字符串编解码、代码美化二维码生成器、编码规范检测、页面性能检测、栅格检测、JS运行效率分析等.
拥有字符串编解码,json串格式化,代码美化,代码压缩,二维码生成,页面取色器,js正则表达式工具(带常用正则),时间(戳)转换,图片Base64,编码规范检测,页面性能检测,Ajax调试功能,简直是WEB开发利器
JSON自动美化(页面自动检测并格式化) JSON手动美化(粘贴文本、手动格式化) JSON比对工具(支持左右两个JSON片段进行键值对比较) 字符串编解码(Unicode/UTF8/Base64/MD5) 代码美化工具...
包含字符串编解码,Json串格式化,代码美化工具,代码压缩工具,二维码生成器,页面取色工具,Js正则表达式,时间(戳)转换,图片Base64,编码规范检测,页面性能检测
这是点云可视化的动态前端,它基于电子和threejs支持ascii和二进制格式的.pcd格式。 当前支持的功能 多个文件比较 彩色标记每个点 GUI更改颜色和磅值 自由方面 信息面板 可视化点云的强度 待办事项 添加对二...
前端神器,包括 JSON 格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试、密码生成器、...
其实所有C系的代码,都可以通过Javascript代码美化工具进行格式化查看 代码压缩 包括Web前端Javascript代码压缩、CSS代码压缩、HTML代码压缩 字符串编解码 包括Unicode编码和解码、UTF-8字符串编码和解码、Base64...
Prettier:代码格式化 Axios:发送网络请求 UnoCSS:具有高性能且极具灵活性的即时原子化 CSS 引擎 注释:各个配置项都写有尽可能详细的注释 兼容移动端: 布局兼容移动端页面分辨率 后端 MySQL 8:关系型数据库
JSON接口自动格式化查看,JSON查看器,代码美化,字符串编解码,图片Base64编码,二维码生成器,二维码解码,全网页截图,时间(戳)转换工具,正则表达式工具,页面取色工具,编码规范检测,页面性能检测
Web前端助手FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试、密码...
FE助手:包括字符串编解码、代码压缩、美化、JSON格式化、正则表达式、时间转换工具、二维码生成与解码、编码规范检测、页面性能检测、页面取色、Ajax接口调试
YOLOv5 + Flask + Vue实现基于深度...Prettier:代码格式化 Axios:发送网络请求 UnoCSS:具有高性能且极具灵活性的即时原子化 CSS 引擎 注释:各个配置项都写有尽可能详细的注释 兼容移动端: 布局兼容移动端页面分辨率
YOLOv5 + Flask + Vue实现基于深度学习算法的...Prettier:代码格式化 Axios:发送网络请求 UnoCSS:具有高性能且极具灵活性的即时原子化 CSS 引擎 注释:各个配置项都写有尽可能详细的注释 兼容移动端: 布局兼容移动端