I have a very simple vue project:
<template>
<div class="text-breakdown">
<h3 class = "title">Text Breakdown</h3>
<form onsubmit="greet()">
<textarea type="text" id = "breakdown-text"
placeholder="Enter your text here">
</textarea>
<button class = "custom-button dark-button"
type="submit">Breakdown</button>
</form>
</div>
</template>
<script>
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
// eslint-disable-next-line no-unused-vars
function greet() {
alert("Hello!");
}
</script>
I get error 'axios' is defined but never used no-unused-vars
error which I'm trying to disable. I tried adding // eslint-disable-next-line no-unused-vars
comment as I've read in some answers would help, but I still get this error!
Removing unused variables is not an option, I don't want this error popping up on unused variables!
EDIT: If I put the comment exactly one line above the import:
<script>
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
// eslint-disable-next-line no-unused-vars
function greet() {
alert("Hello!");
}
...
I get this in browser console:
(and localhost never loads - just white screen)
EDIT:
I tried adding
"rules": {
"no-unused-vars": "off"
}
to the bottom of the package.json
file:
...
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"rules": {
"no-unused-vars": "off"
}
}
and restarting the server, however the error from the pic above is still present - localhost can't be loaded. The error disappears though if I remove the import altogether.
EDIT:
Replacing the script
tag with:
<script>
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
export default {
methods: {
greet() {
alert("Hello!");
}
}
}
</script>
works fine. However removing the comment line:
<script>
import axios from 'axios';
export default {
methods: {
greet() {
alert("Hello!");
}
}
}
</script>
Results in the original error, despite me having edited the package.json
file.
Also, why do I have to add the export default
syntax when using the // eslint
comment with the import
, while just
<script>
// eslint-disable-next-line no-unused-vars
function greet() {
alert("Hello!");
}
</script>
is working fine for me?
ANSWER (because mods didn't deem the solution important enough to allow edit into existing answers):
This code should be added inside eslintConfig:
"rules": {
"no-unused-vars": "off"
}
So that the final eslintConfig
part of the package.json
looks like this:
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"no-unused-vars": "off"
}
}
After editing the package.json like that and restarting the server, this code doesn't result in the error:
<script>
import axios from 'axios';
export default {
methods: {
greet() {
alert("Hello!");
}
}
}
</script>
As can be seen the // eslint... comment is no longer necessary.
See Question&Answers more detail:
os