eslint

Mysterious ESLint Parsing Error

萝らか妹 提交于 2020-01-02 00:54:19
问题 On line 4 of the following code, ESLint is giving me a parsing error saying: Unexpected token = I'm wondering why this is the case? The code runs properly. What am I doing wrong? import { Component, PropTypes } from 'react'; export default class MainApp extends Component { static propTypes = { children: PropTypes.any.isRequired } componentWillMount() { require('./styles/main.styl'); } render() { return ( <div> {this.props.children} </div> ); } } 回答1: You cannot have properties inside classes,

Failed to load plugin @typescript-eslint: Cannot find module 'eslint-plugin-@typescript-eslint'

回眸只為那壹抹淺笑 提交于 2020-01-02 00:13:17
问题 I am reconfiguring my project from tslint to eslint. I can run eslint manually, but webpack fails to run with this error message: Module build failed (from /path/node_modules/eslint-loader/index.js): Error: Failed to load plugin @typescript-eslint: Cannot find module 'eslint-plugin-@typescript-eslint' I have ruled out bad .eslintrc.js and missing dependencies since it works when I run it manually ./node_modules/eslint/bin/eslint.js ./ --ext .ts,.tsx --config ./.eslintrc.js I'm not sure if

学习js的五个不良编码习惯

南楼画角 提交于 2020-01-01 17:25:39
本文根据外网文章译制而来   原文:https://dmitripavlutin.com/unlearn-javascript-bad-coding-habits/   译者:前端小智   为了保证的可读性,本文采用意译而非直译。   在阅读JavaScript代码时,你是否有过这种感觉   你几乎不明白代码的作用?   代码使用了很多 JavaScript 技巧?   命名和编码风格太过随意?   这些都是不良编码习惯的征兆。   在这篇文章中,我描述了JavaScript中常见的5种不良编码习惯。重要的是,本文会给出一些可行的建议,如何的摆脱摆脱这些习惯。   1.不要使用隐式类型转换   JavaScript是一种松散类型的语言。如果使用得当,这是一个好处,因为它给你带来了灵活性。   大多数运算符 +-*/==(不包括 ===)在处理不同类型的操作数时会进行隐式转换。   语句 if(condition){...}, while(condition){...}隐式地将条件转换为布尔值。   下面的示例依赖于类型的隐式转换,这种有时候会让人感到很困惑:   console.log("2" + "1"); // => "21"   console.log("2" - "1"); // => 1   console.log('' == 0); // => true  

如何使用vue-cli创建项目

雨燕双飞 提交于 2019-12-31 22:44:26
如何使用vue-cli创建项目 首先就是对于环境的要求,node.js一定要全局安装,检查自己是否安装的方式 1、win+r 输入cmd 2、输入npm -v检测npm版本,node -v检测node.js版本 准备完毕,开始准备创建项目(截图不便,下面不再截图,文字示之) 其实也简单 npm i -g @vue/cli 安装全局的vue-cli 进入我们要创建项目的目录下 cd D:/testCreate vue init webpack vue-demo(项目名称) 下面是配置项目的一些内容 ?Project name vue-demo # 项目名称,直接回车,按照括号中默认名字(注意这里的名字不能有大写字母,如果有会报错Sorry, name can no longer contain capital letters)。 ? Project description A Vue.js project # 项目描述 ? Author # 作者名称 ? Vue build standalone # 选择运行加编译时 Runtime + Compiler: recommended for most users ? Install vue-router? Yes # 是否需要 vue-router ? Use ESLint to lint your code? Yes # 是否使用

vue脚手架安装以及项目构建

感情迁移 提交于 2019-12-30 02:58:26
安装 cli 命令工具: 1.npm install @vue/cli -g 2.npm install @vue/cli-init -g ( npm install -g @vue/cli @vue/cli-init ) 安装成功后,使用 vue -V 命令,查看版本号; 使用 vue init webpack myapp 构建一个名为 myapp 的项目: Vue 依然使用询问的方式,让我们对项目有一个初始化的信息 Project name:项目名 Project description: 项目描述 Author: 作者 Vue build: 第一种:配合大部分的开发人员 第二种:仅仅中有runtime Install vue-router? 是否安装vue-router Use ESLint to lint your code?是否使用ESLint来验证我们的语法。 Pick an ESLint preser:使用哪种语法规范来检查我们的代码: Standard: 标准规范 Airbnb: 爱彼迎规范 Set up unit test: 设置单元测试 Setup e2e tests: 设置端对端测试 Should we run ‘npm install’:要不要帮忙你下载这个项目需要的第三方包 使用npm来下载 使用yarn来下载 To get started: cd

How to config ESLint for React on Atom Editor

蹲街弑〆低调 提交于 2019-12-29 02:45:25
问题 In Atom Editor I installed the following plugins linter linter-eslint It seems they don't recognize the JSX syntaxis. I have it working on the command line but had to use other plugins like esprima-fb and eslint-plugin-react . Looks like there are no such plugins for Atom Editor and would like to know if anyone of you knows a way to hack around this. 回答1: To get Eslint working nicely with React.js: Install linter & linter-eslint plugins Run npm install eslint-plugin-react Add "plugins": [

手写一个自己的 cli 并发布到 npm 上

偶尔善良 提交于 2019-12-28 23:26:30
手写一个自己的 cli 并发布到 npm 上 简介:大家平时肯定用过 vue-cli 或者 create-react-app,只需要敲简单的命令行,就可以生成一个完成的项目,非常好用。由于本人所在公司接的项目较多,每次新建新项目都是拷贝以前的项目代码,好麻烦,而且得删除掉好多没用的代码,心累。于是就想着模仿 vue-cli 写一个简单的创建项目的 cli,这样不是就省心省力了嘛。于是说干就干,自己写了一个 cli: va-cli ,大家也可以使用,只要执行以下命令就好,如下 npm install va-cli -g va-cli init project-name github 源码地址 下面是实现步骤 1.项目依赖:(先安装,步骤略) "dependencies" : { "chalk" : "^3.0.0" , "commander" : "^4.0.1" , "download-git-repo" : "^3.0.2" , "inquirer" : "^7.0.1" , "ora" : "^4.0.3" } , "devDependencies" : { "eslint" : "^6.8.0" , "eslint-config-standard" : "^14.1.0" , "eslint-plugin-import" : "^2.19.1" , "eslint

vue-cli构建的项目手动添加eslint配置

随声附和 提交于 2019-12-28 13:30:01
一、package.json里配置添加 1.scripts里添加快捷eslint检查命令 "lint": "eslint --ext .js,.vue src" 2.添加eslint依赖包 "babel-eslint": "^8.2.1", "eslint": "^4.15.0", "eslint-config-standard": "^10.2.1", "eslint-friendly-formatter": "^3.0.0", "eslint-loader": "^1.7.1", "eslint-plugin-import": "^2.7.0", "eslint-plugin-node": "^5.2.0", "eslint-plugin-promise": "^3.4.0", "eslint-plugin-standard": "^3.0.1", "eslint-plugin-vue": "^4.0.0", View Code 二、根目录下添加检测配置js文件.eslintrc.js // https://eslint.org/docs/user-guide/configuring module.exports = { root: true, parserOptions: { parser: 'babel-eslint' }, env: { browser: true, },

ESLint with React gives `no-unused-vars` errors

别等时光非礼了梦想. 提交于 2019-12-28 03:29:07
问题 I've setup eslint & eslint-plugin-react . When I run ESLint, the linter returns no-unused-vars errors for each React component. I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas? Example: app.js import React, { Component } from 'react'; import Header from './header.js'; export default class App extends Component { render() { return ( <div> <Header /> {this.props.children} </div> ); } } Linter Errors: /my_project/src/components/app.js 1:8 error 'React' is defined

Array destructuring in JavaScript

徘徊边缘 提交于 2019-12-28 03:03:31
问题 I have this code in my vue-js app: methods: { onSubmit() { ApiService.post('auth/sign_in', { email: this.email, password: this.password, }) .then((res) => { saveHeaderToCookie(res.headers); this.$router.push({ name: 'about' }); }) .catch((res) => { this.message = res.response.data.errors[0]; this.msgStatus = true; this.msgType = 'error'; }); }, } While running Es-lint.. I got an error saying "Use array destructuring" (prefer-destructuring) at this.message = res.response.data.errors[0]; at