eslint

使用命令行工具npm新创建一个vue项目

混江龙づ霸主 提交于 2019-12-24 15:01:44
使用命令行工具npm新创建一个vue项目 使用vue开发项目的前期工作可以参考前面写的: Vue环境搭建及node安装过程整理 Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用。该工具提供开箱即用的构建工具配置,带来现代化的前端开发流程。 只需几分钟即可创建并启动一个带热重载、保存时静态检查以及可用于生产环境的构建配置的项目: # 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpack my-project $ vue init webpack test //输入命令 ? Project name (test) test ? Project name test ? Project description (A Vue.js project) 测试项目 ? Project description 测试项目 ? Author lxx1024 ? Author lxx1024 ? Vue build standalone ? Install vue-router? (Y/n) Y //安装路由 ? Install vue-router? Yes ? Use ESLint to lint your code? (Y/n) n //Eslint验证,很严谨

eslint - disable error notification

烂漫一生 提交于 2019-12-24 12:03:03
问题 I'm coding with brackets and I have eslint installed. Eslint keeps telling me that some functions and var's are defined but never used. I think it is because I'm using an external js file which I linked to my html document. My question is how can I disable this error, or tell eslint to not inform me of this error? 回答1: There are several ways to achieve this. You can disable it inline, by pasting this line in your source: /*eslint-disable no-unused-vars*/ or if you're using .eslintrc file, you

Identifying (gulp-)eslint error reason

心已入冬 提交于 2019-12-24 08:38:00
问题 I have this piece of code: sendMessage(message) { let data = { message }; this.socket.send('message', data); } I'm using eslint and set the object-shorthand rule. "object-shorthand": [ 2, "always" ], And get this error: --- message: 'Unexpected token }' severity: error data: line: 39 column: 14 ruleId: '' ... But why? Any other way to find what rule is being violated? If I do this: sendMessage(message) { let data = { message: message }; this.socket.send('message', data); } I get this: ---

How can I 'force' ALL karma test to fail if an eslint error is found?

非 Y 不嫁゛ 提交于 2019-12-24 08:29:48
问题 I have found that sometimes people do not realise they have linting errors in their tests when they run them since they are show before the test progress/information. Is there any configuration which will cause ALL tests to fail if any of the tests have any linting errors? I am using mocha with karma. Thanks. 回答1: Make the ESLint execution a part of the grunt or gulp or "npm" task (whichever you use). For instance, when we run grunt test , first the ESLint is executed and then karma . If

ESLint: Unexpected block statement surrounding arrow body. (arrow-body-style)

末鹿安然 提交于 2019-12-24 07:49:03
问题 This rule, triggered by the below snippet of code, is most confusing (to me - and others it appears). If I remove the curlies, it breaks. If I add parens around the block, it breaks. What to do? const MainLayout = (props) => { return ( <div className="main"> <Header /> <Navbar /> <Content> {props.children} </Content> <Footer /> </div> ); }; This is ESLint v4.13.1 回答1: if you're just returning a value immediately, you don't need a return statement in an arrow function. Just put the value

ESLint parsing error on Export statement

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:07:08
问题 I'm following a course and the author exports out a Component in the following manner: export MainContainer from './Main/MainContainer' The default correct way is export { default as MainContainer } from './Main/MainContainer' which is not as clean. The author is able to do this with a babel-eslint package, however after I installed that package I still get the lint error. Repo link File structure: Expected No ESlint errors when using export MainContainer from './Main/MainContainer' in

vue-cli关闭eslint及配置eslint

十年热恋 提交于 2019-12-24 06:19:12
有了eslint的校验,可以来规范开发人员的代码,是挺好的。但是有些像缩进、空格、空白行之类的规范,在开发过程中一直报错,有点烦人了。 我们可以在创建工程的时候选择不要安装eslint。就是在安装工程的时候,出现【Use ESLint to lint your code?】时选择【No】即可。 如果你已经安装过了,我们可以直接关闭它。 关闭eslint的方法: 1.项目根目录 ---> build ---> webpack.base.conf.js 注释掉如下的代码 2.重启编辑器,再运行npm run dev 即可。 关闭eslint校验就是这么简单,但是eslint可辅助规范代码风格,有效控制代码质量,并且在多人合作的情况下,也可以使代码看起来更加的整洁。所以在开发过程中,还是建议保留eslint的校验的,养成一个好的编码习惯。那么此时我们可以根据我们项目的需求配置eslint。 配置eslint的方法: 1.打开.eslintrc.js 文件,这个就是eslint的配置文件了 2.根据你的需求添加rules 规则的含义: “off” or 0 - 关闭(禁用)规则 “warn” or 1 - 将规则视为一个警告(并不会导致检查不通过) “error” or 2 - 将规则视为一个错误 (退出码为1,检查不通过) 常用规则: Possible Errors 可能的错误或逻辑错误

Force to store getter result in variable if it is used inside of the loop

孤人 提交于 2019-12-24 03:37:08
问题 Consider following class class Smth { get functionWithSomeVeryUniqueName() { // Some heavy calculations are here return obj => obj; // Actually uses some vars from closure calculated above } } I want to have a tslint error on any access to getter inside of the loop. I. e. any of following lines should be considered bad: for (var x of a) smth.functionWithSomeVeryUniqueName(x); a.forEach(x => smth.functionWithSomeVeryUniqueName(x)) a.map(x => smth.functionWithSomeVeryUniqueName(x)) for (var q=0

Add flow to compilation step on create-react-app project

大憨熊 提交于 2019-12-24 02:56:09
问题 I'm working on a project with create-react-app and would like to add Flow to my process. The official documentation explains how to do this and it's relatively straightforward, but following their instructions it adds it alongside the built in linting/building/compilation that the app does on its own. Based on my understanding, any time I save or make a change to my application code, ESLint is running a style check on my code, Babel is transpiling my ES6 to ES5 JavaScript, and my JSX is being

indentation with eslint on jsx

纵然是瞬间 提交于 2019-12-24 01:43:17
问题 I'm trying to make simple component. But when I click on ctrl + s it does this: warning and error is this: [eslint] Expected closing tag to match indentation of opening. (react/jsx-closing-tag-location) [eslint] Expected indentation of 4 space characters but found 2. (react/jsx-indent) my .eslintrc : { "extends": "airbnb", "parserOptions": { "ecmaFeatures": { "jsx": true, "experimentalObjectRestSpread": true } }, "rules": { "max-len": ["warn", 120], "indent": ["warn", 2], "react/jsx-indent":