728x90 반응형 eslint6 ESLint error: Unnecessary 'else' after 'return'. 에러 메시지 Unnecessary 'else' after 'return'. 코드 vanilla redux에서 reducer 선언하는 중 action의 조건문에서 발생 const countModifier = (count = 0, action) => { console.log(count, action); if (action.type === "ADD") { return count + 1; } else if (action.type === "MINUS") { return count - 1; } return count; }; 해결법 else if문 대신 -> if문 사용 const countModifier = (count = 0, action) => { console.log(count, action); if (act.. 2023. 2. 27. ESlint error: Default parameters should be last. 에러 메시지 Default parameters should be last. 코드 vanilla redux에서 reducer를 선언하는 중 발생 const countModifier = (count = 0, action) => { console.log(count, action); if (action.type === "ADD") { return count + 1; } else if (action.type === "MINUS") { return count - 1; } return count; }; 해결법 https://eslint.org/docs/latest/rules/default-param-last 에는 default paremeter는 무조건 마지막에 넣어주라고 되어있었다. const countModifi.. 2023. 2. 27. ESLint Error: Assignment (=) can be replaced with operator assignment (-=) & Unary operator '--' used 에러 메시지 Assignment (=) can be replaced with operator assignment (-=). Unary operator '--' used 코드 간단한 숫자 카운터 만드는 중 증감식에서 발생 const handleAdd = () => { count = count + 1; }; const handleMinus = () => { count--; }; 해결 const handleAdd = () => { count += 1; }; const handleMinus = () => { count -= 1; }; 2023. 2. 27. eslint Error: A form label must be associated with a control. 에러 메시지 A form label must be associated with a control. eslint (jsx-a11y/label-has-associated-control) -> label은 input과 연관되어야 한다 에러 코드 이메일 에러 원인 htmlFor과 id로 연결해도 에러 발생 -> React에서는 컴포넌트 재상요으로 인해 id의 유일성 보장하기 못하기 때문 (map()으로 리스트를 만들 때 key값에 index를 넣었을 때도 비슷한 문제가 발생했었다) 해결 방법 2가지 [1] .eslint.json에 아래 내용 추가 { "rules": { "jsx-a11y/label-has-associated-control": [ 2, { "labelAttributes": ["htmlFor"] }.. 2023. 2. 16. eslint 오류: Expected property shorthand eslint(object-shorthand) 발단 클래스 컴포넌트에서 board state를 같은 board로 변경해주는 커스텀 메서드를 선언하는 부분에서 eslint 에러 발생 this.state = { board: [], } getDetail = () => { this.setState({ board: board, }); } 에러 메시지 ES6 문법에서 좀 더 간단하게 표현할 수 있는 문법이 생겼다. 그걸 써라는 말임. Expected property shorthand eslint(object-shorthand) // es5 var foo = { x: x, y: y, z: z, }; // es6 var foo = { x, y, z }; // es5 var foo = { a: function() {}, b: function() {} }; // es.. 2023. 1. 31. eslint 오류: State initialization should be in a constructor eslint(react/state-in-constructor) 발단 조금 예전 리액트 강의들을 따라하다보면 함수형 컴포넌트보다는 클래스형 컴포넌트를 사용한 것들이 많고, 클래스형 컴포넌트에서 state의 초깃값 정의 부분도 constructor() 생성자 함수 없이 그냥 곧바로 정의해주는 경우가 많았다. class Header extends Component { state = { buttonDisplay: "none" }; 에러 메시지 이는 eslint 오류를 발생시키는데, 바로, class 컴포넌트의 state의 초깃값 설정 부분은 constructor() 생성자 함수 안에 들어가야한다는 것이다 State initialization should be in a constructor eslint(react/state-in-constructor) 해결 state 초깃값.. 2023. 1. 31. 이전 1 다음 728x90 반응형