개발/기타
[eslint] warning Unexpected console statement no-console 해결방법
남양주개발자
2020. 12. 18. 09:00
728x90
반응형
프로젝트에 eslint를 설정하고나면 eslint의 룰(Rules)로 인해 console 메서드에 대한 warning 메시지가 출력되곤 합니다. 개발단계에서 이러한 경고 메시지가 조금 거슬리는 경우가 있는데요. eslint 룰를 조금만 수정해주면 해당 console 문구에 대한 경고 메세지를 제거할 수 있습니다.
no-console - Rules
disallow the use of console (no-console) In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable t
eslint.org
// .eslintrc
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
parserOptions: {
parser: 'babel-eslint',
},
extends: [
'@nuxtjs',
'prettier',
'prettier/vue',
'plugin:prettier/recommended',
'plugin:nuxt/recommended',
],
plugins: ['prettier'],
// add your custom rules here
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', // 추가
},
}
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', // 추가
만약 프로젝트에서 console에 대한 설정을 off로 하고 싶다면 'no-console': 'off'로 설정하면 됩니다. 제대로 설정된 것을 확인하기 위해서는 프로젝트를 재시작하면 됩니다. 프로젝트를 재시작하면 기존에 warn으로 경고를 내던 문구들이 사라진 것을 확인할 수 있습니다.
728x90
반응형
그리드형