vue項(xiàng)目啟動(dòng)報(bào)錯(cuò) error Parsing error: missing-semicolon-after-chara
問題:今天拉取代碼后,啟動(dòng)項(xiàng)目提示 ?error ?Parsing error: missing-semicolon-after-chara; 解析的錯(cuò)誤:字符后缺少分號(hào)。

找文件:找到錯(cuò)誤文件發(fā)
發(fā)現(xiàn)代碼有紅色波浪線體提示
將鼠標(biāo)移動(dòng)到錯(cuò)誤代碼塊上,有更詳細(xì)的錯(cuò)誤提示,提示內(nèi)容和啟動(dòng)項(xiàng)目時(shí)的錯(cuò)誤一致
觀察錯(cuò)誤提示,發(fā)現(xiàn)使用了eslint-plugin-vue
發(fā)現(xiàn)項(xiàng)目中.eslintrc.js文件以前都沒有注意過
module.exports = { root: true, env: { node: true }, extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"], parserOptions: { parser: "babel-eslint" }, rules: { "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", "no-unused-vars": "off", // 多余變量檢查,聲明了多余變量但沒使用 "no-irregular-whitespace": "off", //這禁止掉 空格報(bào)錯(cuò)檢查 "prettier/prettier": "off"http://關(guān)閉prettier } }; “off” 或 0 - 關(guān)閉規(guī)則 “warn” 或 1 - 開啟規(guī)則 “error” 或 2 - 開啟規(guī)則
ESLint的用途
1.審查代碼是否符合編碼規(guī)范和統(tǒng)一的代碼風(fēng)格;
2.審查代碼是否存在語法錯(cuò)誤;
ESLint的介紹
About ESLint is an open source JavaScript linting utility originally created by Nicholas C. Zakas in June 2013. Code linting is a type of static analysis that is frequently used to find problematic patterns or code that doesn’t adhere to certain style guidelines. There are code linters for most programming languages, and compilers sometimes incorporate linting into the compilation process. ESLint 是一個(gè)開源的 JavaScript 代碼檢查工具,由 Nicholas C. Zakas 于2013年6月創(chuàng)建。代碼檢查是一種靜態(tài)的分析,常用于尋找有問題的模式或者代碼,并且不依賴于具體的編碼風(fēng)格。對(duì)大多數(shù)編程語言來說都會(huì)有代碼檢查,一般來說編譯程序會(huì)內(nèi)置檢查工具。 JavaScript, being a dynamic and loosely-typed language, is especially prone to developer error. Without the benefit of a compilation process, JavaScript code is typically executed in order to find syntax or other errors. Linting tools like ESLint allow developers to discover problems with their JavaScript code without executing it. JavaScript 是一個(gè)動(dòng)態(tài)的弱類型語言,在開發(fā)中比較容易出錯(cuò)。因?yàn)闆]有編譯程序,為了尋找 JavaScript 代碼錯(cuò)誤通常需要在執(zhí)行過程中不斷調(diào)試。像 ESLint 這樣的可以讓程序員在編碼的過程中發(fā)現(xiàn)問題而不是在執(zhí)行的過程中。 The primary reason ESLint was created was to allow developers to create their own linting rules. ESLint is designed to have all rules completely pluggable. The default rules are written just like any plugin rules would be. They can all follow the same pattern, both for the rules themselves as well as tests. While ESLint will ship with some built-in rules to make it useful from the start, you’ll be able to dynamically load rules at any point in time. ESLint 的初衷是為了讓程序員可以創(chuàng)建自己的檢測(cè)規(guī)則。ESLint 的所有規(guī)則都被設(shè)計(jì)成可插入的。ESLint 的默認(rèn)規(guī)則與其他的插件并沒有什么區(qū)別,規(guī)則本身和測(cè)試可以依賴于同樣的模式。為了便于人們使用,ESLint 內(nèi)置了一些規(guī)則,當(dāng)然,你可以在使用過程中自定義規(guī)則。 ESLint is written using Node.js to provide a fast runtime environment and easy installation via npm. ESLint 使用 Node.js 編寫,這樣既可以有一個(gè)快速的運(yùn)行環(huán)境的同時(shí)也便于安裝。 Philosophy Everything is pluggable: 所有都是可拔插的 Rule API is used both by bundled and custom rules 內(nèi)置規(guī)則和自定義規(guī)則共用一套規(guī)則 API Formatter API is used both by bundled and custom formatters 內(nèi)置的格式化方法和自定義的格式化方法共用一套格式化 API Additional rules and formatters can be specified at runtime 額外的規(guī)則和格式化方法能夠在運(yùn)行時(shí)指定 Rules and formatters don’t have to be bundled to be used 規(guī)則和對(duì)應(yīng)的格式化方法并不強(qiáng)制捆綁使用 Every rule: 每條規(guī)則: Is standalone 各自獨(dú)立 Can be turned off or on (nothing can be deemed “too important to turn off”) 可以開啟或關(guān)閉(沒有什么可以被認(rèn)為“太重要所以不能關(guān)閉”) Can be set to a warning or error individually 可以將結(jié)果設(shè)置成警告或者錯(cuò)誤 Additionally: 另外: Rules are “agenda free” - ESLint does not promote any particular coding style ESLint 并不推薦任何編碼風(fēng)格,規(guī)則是自由的 Any bundled rules are generalizable 所有內(nèi)置規(guī)則都是泛化的 The project: 項(xiàng)目: Values documentation and clear communication 通過豐富文檔減少溝通成本 Is as transparent as possible 盡可能的簡(jiǎn)單透明 Believes in the importance of testing 相信測(cè)試的重要性
ESLint的配置
ESlint 被設(shè)計(jì)為完全可配置的,這意味著你可以關(guān)閉每一個(gè)規(guī)則而只運(yùn)行基本語法驗(yàn)證,或混合和匹配 ESLint 默認(rèn)綁定的規(guī)則和你的自定義規(guī)則,以讓 ESLint 更適合你的項(xiàng)目。有兩種主要的方式來配置 ESLint: Configuration Comments - 使用 JavaScript 注釋把配置信息直接嵌入到一個(gè)代碼源文件中。 Configuration Files - 使用 JavaScript、JSON 或者 YAML 文件為整個(gè)目錄(處理你的主目錄)和它的子目錄指定配置信息。可以配置一個(gè)獨(dú)立的 .eslintrc.* 文件,或者直接在 package.json 文件里的 eslintConfig 字段指定配置,ESLint 會(huì)查找和自動(dòng)讀取它們,再者,你可以在命令行運(yùn)行時(shí)指定一個(gè)任意的配置文件。 如果你在你的主目錄(通常 ~/)有一個(gè)配置文件,ESLint 只有在無法找到其他配置文件時(shí)才使用它。 有很多信息可以配置: Environments - 指定腳本的運(yùn)行環(huán)境。每種環(huán)境都有一組特定的預(yù)定義全局變量。 Globals - 腳本在執(zhí)行期間訪問的額外的全局變量。 Rules - 啟用的規(guī)則及其各自的錯(cuò)誤級(jí)別。 所有這些選項(xiàng)讓你可以細(xì)粒度地控制 ESLint 如何對(duì)待你的代碼。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。