当前位置: 首页 > news >正文

国家建设厅网站建设永久网站

国家建设厅网站,建设永久网站,大气 网站模板,中国互联网前100名企业ESLint 是一个广泛使用的 JavaScript 代码检查工具#xff0c;可以帮助开发者在编写代码时发现并修复潜在的问题和错误。 在 第一步 创建工程 时虽然已经选择了包含 ESLint 预设配置#xff0c;但还需要做一些调整#xff0c;让我们使用起来能够更加的丝滑。 vue.config.j…ESLint 是一个广泛使用的 JavaScript 代码检查工具可以帮助开发者在编写代码时发现并修复潜在的问题和错误。 在 第一步 创建工程 时虽然已经选择了包含 ESLint 预设配置但还需要做一些调整让我们使用起来能够更加的丝滑。 vue.config.js 检测开关和模式 module.exports {// 是否每次保存时 lint 代码,可选值 (boolean | warning | default | error) 默认 defaultlintOnSave: default }如不想使用 ESLint 将值设置为false即可。 具体可以参考 Vue CLI 官方文档中的 vue.config.js lintOnSave 配置参考 配置方式1 1.1 package.json 中 eslintConfig 模块说明 在你的项目根目录下找到一个名为 package.json 的文件并找到文件中 eslintConfig 模块块当前版本内容如下所示 eslintConfig: {root: true,env: {node: true},extends: [plugin:vue/essential,eslint:recommended],parserOptions: {parser: babel/eslint-parser},rules: {} }这个部分配置定义了一些ESLint的基本配置选项 root: true 指定此配置文件为根配置文件即停止在父级目录中寻找其他配置文件。env: {node: true} 指定代码的环境为 Node.js 环境在 Node.js 项目中使用 ESLint 时需要设置。extends: [plugin:vue/essential, eslint:recommended] 继承的 ESLint 配置。在此配置中继承了 Vue 的插件 plugin:vue/essential 和 ESLint 的推荐配置 eslint:recommended 。plugin:vue/essential 提供了一组用于 Vue.js 项目的 ESLint 规则eslint:recommended 提供了一组广泛认可的通用规则。parserOptions: {parser: babel/eslint-parser} 指定 ESLint 解析代码的解析器。在这个例子中使用了babel/eslint-parser它是一个基于 Babel 的解析器可用于支持 ES6 语法特性。rules: {} 可以用于设置和自定义 ESLint 的规则。您可以在这里添加和修改规则以符合您的代码风格和要求。 1.2 配置忽略检测 在 eslintConfig 模块中添加以下内容 eslintConfig: {ignorePatterns: [/node_modules/,/dist/,/public/,*.config.js] }通过这个配置您可以告诉 ESLint 忽略这些文件和文件夹避免对不需要进行 ESLint 检查的文件进行无用的检查提高检查效率。 以下是一些.eslintignore文件的示例规则 **/*.js 忽略所有的.js文件 /node_modules/ 忽略特定的目录及其所有子目录 filename.js 忽略特定的文件 path/to/filename.js 忽略某个具体路径的文件 更多的细节和示例可以在 ESLint官方文档 中找到.eslintignore的文档 1.3 配置验证规则 在 eslintConfig 模块中 找到 rules 模块添加自己想要的规则 rules: {no-console: 1 }规则配置用于定义代码中的规则或约定帮助开发者编写更具可读性和可维护性的代码。在这里 no-console 规则用于检测代码中是否使用了 console 对象的方法 对于规则的值ESLint使用以下三种不同类型的配置 off 或 0 表示关闭该规则不会对代码进行检查。 warn 或 1 表示开启该规则并将违反规则的地方报告为警告但不会阻止代码的执行。 error 或 2 表示开启该规则并将违反规则的地方报告为错误会阻止代码的执行。 配置方式2当前deom采用的方式 2.1 配置忽略检测 在根目录下创建 .eslintignore 文件 .eslintignore文件是用来配置ESLint忽略特定文件或目录的配置文件。当ESLint对代码进行静态分析时它会检查项目中的所有文件包括代码中的所有目录和文件。但是有时候我们可能希望ESLint忽略某些文件或目录以避免对它们进行规范检查。 .eslintignore文件基本上是一个包含忽略规则的文本文件。每一行表示一个忽略规则规则可以是通配符模式或具体的文件路径。 以下是当前demo工程的.eslintignore文件中的配置内容,可作为参考 /node_modules/ /dist/ /public/ *.config.js以下是一些.eslintignore文件的示例规则 **/*.js 忽略所有的.js文件 /node_modules/ 忽略特定的目录及其所有子目录 filename.js 忽略特定的文件 path/to/filename.js 忽略某个具体路径的文件 更多的细节和示例可以在 ESLint官方文档 中找到.eslintignore的文档 无论是使用.eslintignore文件还是在eslintConfig中配置ignorePatterns都可以指定要忽略的文件或目录的路径。这样ESLint 将不会对这些文件进行任何检查。 请注意.eslintignore文件优先于eslintConfig中的ignorePatterns即如果两者都存在ESLint将优先考虑.eslintignore文件中的配置。 2.2 配置验证规则 在根目录新建 .eslintrc.js 文件添加以下代码 module.exports {// 指定此配置文件为根配置文件即停止在父级目录中寻找其他配置文件。root: true,// 指定代码的环境为 Node.js 环境在 Node.js 项目中使用 ESLint 时需要设置。env: {node: true,},// 继承的 ESLint 配置。在此配置中继承了 Vue 的插件 plugin:vue/essential。它提供了一组用于 Vue.js 项目的 ESLint 规则。extends: [plugin:vue/essential],// 指定全局变量以告诉 ESLint 在验证过程中这些变量已经定义从而避免产生未定义变量的警告globals: {},// 指定 ESLint 解析代码的解析器parserOptions: {ecmaVersion: 2018,sourceType: module,},// 可以用于设置和自定义 ESLint 的规则。您可以在这里添加和修改规则以符合您的代码风格和要求rules: {} }以下是当前demo中的 .eslintrc.js 完整配置代码以供参考 const msgType process.env.NODE_ENV development ? 1 : 2 // 规则提示类型module.exports {// 指定此配置文件为根配置文件即停止在父级目录中寻找其他配置文件。root: true,// 指定代码的环境为 Node.js 环境在 Node.js 项目中使用 ESLint 时需要设置。env: {node: true,},// 继承的 ESLint 配置。在此配置中继承了 Vue 的插件 plugin:vue/essential。它提供了一组用于 Vue.js 项目的 ESLint 规则。extends: [plugin:vue/essential],// 指定全局变量以告诉 ESLint 在验证过程中这些变量已经定义从而避免产生未定义变量的警告globals: {},// 指定 ESLint 解析代码的解析器parserOptions: {ecmaVersion: 2018,sourceType: module,},// 可以用于设置和自定义 ESLint 的规则。您可以在这里添加和修改规则以符合您的代码风格和要求rules: {vue/multi-word-component-names: 0, // 组件件名称是否以驼峰格式命名strict: 2, // 使用严格模式no-alert: 2, // 禁止使用alert confirm promptno-console: [process.env.ENV_KEY development ? 0 : 1, { allow: [warn, error] }], // 禁止使用console, 只能使用console.warn console.errorno-debugger: process.env.NODE_ENV development ? 0 : 2, // 禁止使用debuggerprefer-arrow-callback: msgType, // 首选箭头函数prefer-const: msgType, // 首选constprefer-spread: msgType, // 首选展开运算prefer-template: msgType, // 首选模板字符串quotes: [msgType, single], // 引号类型 // quote-props: [msgType, always], // 对象字面量中的属性名是否强制双引号jsx-quotes: [msgType, prefer-double], // 强制在 JSX 属性中一致使用双引号或单引号no-useless-concat: msgType, // 不允许两个字符串连接在一起no-multi-str: msgType, // 字符串不能用\换行no-new: msgType, // 禁止在使用new构造一个实例后不赋值no-new-func: msgType, // 禁止使用new Functionno-new-object: msgType, // 禁止使用new Object()no-new-require: msgType, // 禁止使用new requireno-new-wrappers: msgType, // 禁止使用new创建包装实例new String new Boolean new Numberno-array-constructor: msgType, // 不允许使用Array构造函数semi: [msgType, never], // 语句强制分号结尾semi-spacing: [msgType, { before: false, after: true }], // 分号前后空格no-extra-semi: msgType, // 禁止多余的分号func-style: [msgType, expression], // 使用函数表达式no-underscore-dangle: msgType, // 标识符不能以_开头或结尾no-await-in-loop: msgType, // 不允许await在循环体内使用no-bitwise: msgType, // 不允许按位运算符no-buffer-constructor: msgType, // 不允许调用和构造Buffer()构造函数no-caller: msgType, // 阻止使用已弃用和次优代码no-catch-shadow: msgType, // 禁止catch子句参数与外部作用域变量同名no-cond-assign: msgType, // 禁止在条件表达式中使用赋值语句no-confusing-arrow: msgType, // 不在可能与比较运算符混淆的地方使用箭头函数语法no-const-assign: msgType, // 禁止修改const声明的常量no-constant-condition: msgType, // 禁止在条件中使用常量表达式 if(true) if(1)no-continue: msgType, // 禁止使用continueno-control-regex: msgType, // 禁止在正则表达式中使用控制字符no-delete-var: msgType, // 不能对var声明的变量使用delete操作符no-div-regex: msgType, // 不能使用看起来像除法的正则表达式/foo/no-dupe-args: msgType, // 函数参数不能重复no-dupe-class-members: msgType, // 类成员中不能有相同名称的声明no-dupe-keys: msgType, // 在创建对象字面量时不允许键重复 {a:1,a:1}no-duplicate-case: msgType, // switch中的case标签不能重复no-duplicate-imports: msgType, // 从单个模块进行的所有导入都以单一import语句存在no-empty: msgType, // 块语句中的内容不能为空no-empty-character-class: msgType, // 正则表达式中的[]内容不能为空no-eq-null: 0, // 禁止对null使用或!运算符no-eval: msgType, // 禁止使用evalno-ex-assign: msgType, // 禁止给catch语句中的异常参数赋值no-extend-native: msgType, // 禁止扩展native对象no-extra-bind: msgType, // 禁止不必要的函数绑定no-extra-boolean-cast: msgType, // 禁止不必要的boolean转换no-extra-label: msgType, // 消除不必要的标签no-extra-parens: msgType, // 禁止非必要的括号no-fallthrough: msgType, // 禁止switch穿透no-floating-decimal: msgType, // 禁止省略浮点数中的0 .5 3.no-func-assign: msgType, // 禁止重复的函数声明no-global-assign: msgType, // 不允许修改只读全局变量no-implicit-coercion: msgType, // 禁止隐式转换no-implied-eval: msgType, // 禁止使用隐式evalno-inner-declarations: [msgType, functions], // 禁止在块语句中使用声明变量或函数no-invalid-regexp: msgType, // 禁止无效的正则表达式no-invalid-this: msgType, // 禁止无效的this只能用在构造器类对象字面量no-irregular-whitespace: msgType, // 不能有不规则的空格no-iterator: msgType, // 禁止使用__iterator__ 属性no-label-var: msgType, // label名不能与var声明的变量名相同no-labels: msgType, // 禁止标签声明no-lone-blocks: msgType, // 禁止不必要的嵌套块no-lonely-if: 0, // 将if语句作为else块中的唯一语句no-mixed-operators: [msgType, {groups: [[,!,,!,,,,], [,||]]}], // 复杂的表达式使用括号no-mixed-spaces-and-tabs: msgType, // 禁止混用tab和空格no-multi-spaces: msgType, // 不能用多余的空格no-multiple-empty-lines: [msgType, { max: 1 }], // 空行最多不能超过1行no-negated-condition: msgType, // 禁止不必要的否定条件no-negated-in-lhs: msgType, // in 操作符的左边不能有!no-nested-ternary: msgType, // 禁止使用嵌套的三目运算no-obj-calls: msgType, // 不能调用内置的全局对象比如Math() JSON()no-octal: msgType, // 禁止使用八进制数字no-octal-escape: msgType, // 禁止使用八进制转义序列no-param-reassign: msgType, // 禁止给参数重新赋值no-process-exit: msgType, // 禁止使用process.exit()no-proto: msgType, // 禁止使用__proto__属性no-redeclare: msgType, // 禁止重复声明变量no-regex-spaces: msgType, // 禁止在正则表达式字面量中使用多个空格 /foo bar/no-return-assign: msgType, // return 语句中不能有赋值表达式no-script-url: msgType, // 禁止使用javascript:void(0)no-self-compare: msgType, // 不能比较自身no-sequences: msgType, // 禁止使用逗号运算符no-shadow: msgType, // 外部作用域中的变量不能与它所包含的作用域中的变量或参数同名no-shadow-restricted-names: msgType, // 严格模式中规定的限制标识符不能作为声明时的变量名使用no-spaced-func: msgType, // 函数调用时 函数名与()之间不能有空格no-sparse-arrays: msgType, // 禁止稀疏数组 [1,,2]no-trailing-spaces: msgType, // 一行结束后面不要有空格no-throw-literal: msgType, // 禁止抛出字面量错误 throw error;no-undef: msgType, // 不能有未定义的变量no-undef-init: msgType, // 变量初始化时不能直接给它赋值为undefinedno-undefined: msgType, // 不能使用undefinedno-unexpected-multiline: msgType, // 避免多行表达式no-unneeded-ternary: msgType, // 禁止不必要的嵌套 var isYes answer 1 ? true : false;no-unreachable: msgType, // 不能有无法执行的代码no-unused-expressions: msgType, // 禁止无用的表达式no-unused-vars: [msgType, { vars: all, args: none }], // 不能有声明后未被使用的变量或参数no-use-before-define: msgType, // 未定义前不能使用no-useless-call: msgType, // 禁止不必要的call和applyno-void: msgType, // 禁用void操作符no-var: msgType, // 禁用var用let和const代替no-with: msgType, // 禁用witharray-bracket-spacing: [msgType, never], // 是否允许非空数组里面有多余的空格arrow-parens: [msgType, always], // 箭头函数用小括号括起来arrow-spacing: [msgType, { before: true, after: true }], // 的前/后括号block-scoped-var: msgType, // 块语句中使用varbrace-style: [msgType, 1tbs], // 大括号风格camelcase: msgType, // 强制驼峰法命名comma-dangle: [msgType, never], // 对象字面量项尾不能有逗号comma-spacing: [msgType, { before: false, after: true }], // 逗号前后的空格comma-style: [msgType, last], // 逗号风格换行时在行首还是行尾consistent-this: [msgType, self], // this别名curly: [msgType, all], // 必须使用 if(){} 中的{}default-case: msgType, // switch语句最后必须有defaultdot-location: [msgType, object], // 对象访问符的位置换行的时候在行首还是行尾eqeqeq: 0, // 必须使用全等func-names: [msgType, never], // 函数表达式必须有名字indent: [msgType, 2], // 缩进风格init-declarations: [msgType, always], // 声明时必须赋初值key-spacing: [msgType, { beforeColon: false, afterColon: true }], // 对象字面量中冒号的前后空格max-depth: [msgType, 5], // 嵌套块深度max-nested-callbacks: [msgType, 3], // 回调嵌套深度max-params: [msgType, 5], // 函数最多只能有几个参数object-curly-spacing: [msgType, always], // 大括号内是否允许不必要的空格object-shorthand: msgType, // 强制对象字面量缩写语法one-var: [msgType, never], // 连续声明operator-assignment: [msgType, never], // 赋值运算符 -什么的operator-linebreak: [msgType, after], // 换行时运算符在行尾还是行首padded-blocks: [msgType, never], // 块语句内行首行尾是否要空行radix: msgType, // parseInt必须指定第二个参数space-before-blocks: [msgType, always], // 不以新行开始的块{前面要不要有空格space-before-function-paren: [msgType, never], // 函数定义时括号前面要不要有空格space-in-parens: [msgType, never], // 小括号里面要不要有空格space-unary-ops: [msgType, { words: true, nonwords: false }], // 一元运算符的前/后要不要加空格use-isnan: msgType, // 禁止比较时使用NaN只能用isNaN()spaced-comment: [msgType, always], // 注释一致性no-path-concat: 0, // node中不能使用__dirname或__filename做路径拼接no-process-env: 0, // 禁止使用process.envno-restricted-modules: 0, // 禁用指定node.js模块使用就会报错no-sync: 0, // nodejs 禁止同步方法newline-after-var: 0, // 变量声明后是否需要空一行} }最终根据当前deom的最终配置可删除以下内容避免无用代码导致维护成本增加 package.json 中 babel/eslint-parser 开发依赖。package.json 中 eslintConfig 代码块 。如果 .eslintignore 文件存在便删除。 代码中的忽略检测 /* eslint-disable */ 在文件开头禁用 eslint 检查 /* eslint-disable no-alert, quotes */ 在文件开头禁用 eslint 指定规则检查 // eslint-disable-line 单行禁用eslint检查 // eslint-disable-line no-alert, quotes 单行禁用指定规则检查 // eslint-disable-next-line 禁用下一行eslint检查 // eslint-disable-next-line no-alert, quotes 下一行禁用指定规则检查 框架搭建整体流程 第一步 Vue2 使用 Vue 脚手架 Vue CLI 搭建一个 Vue.js 前端项目框架第二步 Vue2 vue.config.js 基础配置路径别名alias第三步 Vue2 vue.config.js 集成 Less 配置 sourceMap全局变量第四步 Vue2 配置ESLint第五步 Vue2 vue.config.js 使用image-minimizer-webpack-plugin配置图片压缩第六步 Vue2 集成全家桶 vue-router vuex axios 和 element-ui第七步 Webpack 配置多环境和全局变量 cross-env 和 webpack.DefinePlugin 点击下载步骤 1-7 配置完成的完整 Demo
http://www.w-s-a.com/news/237740/

相关文章:

  • 建设网站是普通办公吗快速排名seo软件
  • 大型外贸网站建设网站建设图片尺寸要求
  • 网站建设可信赖北京网站开发月薪
  • 专门做lolh的网站wordpress 模版 cho's
  • 网上做设计兼职哪个网站好点网站开发毕业周记
  • 自学商城网站建设无为网页定制
  • wordpress全站cdn手机网站调用分享
  • 淄博做网站58同城wordpress微信号订阅
  • 不同的网站 做301公共资源交易中心是干嘛的
  • 36 氪 网站如何优化怎么优化自己的网站
  • 网站兼容问题湖北网站建设优化
  • 2018新网站做外链app制作的网站
  • 外贸网站建设怎么建设pc网站做移动端适配
  • 做经销找厂家好的网站个人备案网站可以做电影站吗
  • 网站搭建怎么做网站建设培训哪家好
  • 学做美食的视频网站企业网站备案密码怎么找回
  • 销售产品做单页还是网站seo有哪些作用
  • 网站视觉规范南宁网站优化推广
  • 公司起名打分最准的免费网站学设计的学校
  • 用cn作网站行么WordPress网站打不开nginx
  • 顺德龙江网站建设百货商城自助下单网站
  • 门户网站采用较多的模式是wordpress自动搜索缩略图
  • 深圳设计功能网站做网站推广怎么做
  • 海口专业网站建设地址wordpress站点标题是什么
  • 青岛做网站那家好网页素材网
  • 宁夏银川做网站的公司网络营销有哪些推广方法
  • 免费域名网站哪个最好东莞企业网站排名
  • dz做网站网址模版
  • 做外贸网站平台中华室内设计师网
  • 三大网络架构seo是啥职业