eslint

React使用hook

时间秒杀一切 提交于 2021-02-12 09:01:16
Hook 是 React 16.8 的新增特性。它可以让你在不编写 class 的情况下使用 state 以及其他的 React 特性。 为什么会有hook 在组件之间复用状态逻辑很难,需要重新组织你的组件结构,抽象层组成的组件会形成“嵌套地狱” 复杂组件变得难以理解,各生命周期交叉副作用 State Hook import React, { useState } from 'react'; // 引入 function Example() { // 声明一个叫 "count" 的 state 变量 const [count, setCount] = useState(0); return ( <div> <p>You clicked {count} times</p> // 使用 <button onClick={() => setCount(count + 1)}> // 改变 Click me </button> </div> ); } Hook 在 class 内部是不起作用的。但你可以使用它们来取代 class 。 useState 需要哪些参数? useState() 方法里面唯一的参数就是初始 state。不同于 class 的是,我们可以按照需要使用数字或字符串对其进行赋值,而不一定是对象。在示例中,只需使用数字来记录用户点击次数,所以我们传了 0 作为变量的初始

Eslint angular and jasmine: is not defined no-undef

夙愿已清 提交于 2021-02-11 16:51:27
问题 I am trying to lint my angular code using angular, eslint:recommended and the jasmine plugin recommended settings. However I get is not defined errors on the jasmine stuff. My eslint file looks like this: { "plugins": ["jasmine"], "extends": ["angular", "eslint:recommended", "plugin:jasmine/recommended"], "rules": { "quotes": [ 2, "single"], "strict": [2, "global"], "semi": ["error", "always"], "angular/on-watch": "warn" } } I get the following errors: 3:1 error 'describe' is not defined no

Is there a typescript-eslint rule that alerts you when you use a method as a boolean?

前提是你 提交于 2021-02-11 16:30:48
问题 In Javascript, I sometimes accidentally write: if (obj.method) { // <-- bad ... } instead of if (obj.method()) { // <-- good ... } Given that typescript-eslint is typeaware, is there a rule that detects this usage? I would say that 99/100 times, I am not trying to use the method as a boolean. 回答1: If you turn on typescript's strictNullChecks compiler option (or the catch-all strict compiler option), TS will do this specific check for you automatically! Example: https://www.typescriptlang.org

Is there a typescript-eslint rule that alerts you when you use a method as a boolean?

南笙酒味 提交于 2021-02-11 16:27:49
问题 In Javascript, I sometimes accidentally write: if (obj.method) { // <-- bad ... } instead of if (obj.method()) { // <-- good ... } Given that typescript-eslint is typeaware, is there a rule that detects this usage? I would say that 99/100 times, I am not trying to use the method as a boolean. 回答1: If you turn on typescript's strictNullChecks compiler option (or the catch-all strict compiler option), TS will do this specific check for you automatically! Example: https://www.typescriptlang.org

ESLint error when trying to lint Angular templates

杀马特。学长 韩版系。学妹 提交于 2021-02-10 15:58:08
问题 I have an Angular 10 app set up with eslint and prettier, which worked fine so far for linting Typescript files. I'm now trying to lint my component template files as well following this doc. But when I run it with eslint . --ext .js,.ts,.component.html --fix I keep getting Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript

ESLint error when trying to lint Angular templates

被刻印的时光 ゝ 提交于 2021-02-10 15:56:59
问题 I have an Angular 10 app set up with eslint and prettier, which worked fine so far for linting Typescript files. I'm now trying to lint my component template files as well following this doc. But when I run it with eslint . --ext .js,.ts,.component.html --fix I keep getting Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript

error '_' is not defined no-undef

拜拜、爱过 提交于 2021-02-10 10:18:23
问题 I use eslint to check my code ,and a error happen -- "error '_' is not defined no-undef". I write the code like this: new webpack.ProvidePlugin({ $: "jquery",//jquery jQuery: "jquery", "window.jQuery": "jquery", _:"lodash"//lodash }) and get .eslintrc.js, part of it like this: "env": { "browser": true, "commonjs": true, "es6": true, "jquery":true, }, before I add the jquery into ,it happen an error -- "error '_' is not defined no-undef". However, when I add lodash into ,just like that "

Limit maximum number of errors

寵の児 提交于 2021-02-10 06:32:32
问题 How to limit maximum number of error in eslint through .eslintrc. My current .eslintrc module.exports = { "extends": "airbnb", "parserOptions": { "ecmaVersion": 6 }, "max-warnings" : 2 }; 回答1: Currently, max-warnings is a command-line only option. You can't define it in a .eslintrc file. See eslint#2769. There are a couple of alternatives you can use, depending on how you are runnning eslint. You can use something like eslint-nibble to address a subset of the errors one at a time, and see

Must use destructuring props assignment [duplicate]

两盒软妹~` 提交于 2021-02-08 19:44:13
问题 This question already has an answer here : Must use destructuring props assignment (react/destructuring-assignment) (1 answer) Closed last month . I'm using Eslint in my React Native project, and in this code: export default class AuthLoadingScreen extends React.Component { constructor() { super(); this.bootstrapAsync(); } bootstrapAsync = async () => { const userToken = await AsyncStorage.getItem('userToken'); this.props.navigation.navigate(userToken ? 'App' : 'Auth'); }; render() { return (

Must use destructuring props assignment [duplicate]

断了今生、忘了曾经 提交于 2021-02-08 19:44:08
问题 This question already has an answer here : Must use destructuring props assignment (react/destructuring-assignment) (1 answer) Closed last month . I'm using Eslint in my React Native project, and in this code: export default class AuthLoadingScreen extends React.Component { constructor() { super(); this.bootstrapAsync(); } bootstrapAsync = async () => { const userToken = await AsyncStorage.getItem('userToken'); this.props.navigation.navigate(userToken ? 'App' : 'Auth'); }; render() { return (