eslint: disable warning - `defined but never used` for specific function?
Provide a config comment telling it to ignore that rule (defined but never used is the no-unused-vars
rule)
function render() { // eslint-disable-line no-unused-vars
// do stuff
var x; // still raises defined but never used
}
Vue: disable no-unused-vars error: the simplest fix
You are using eslint, which add rules to your code, no unused vars
is one of them, which means you aren't allowed to have unused variable in your code, so importing axios variable from import axios from'axios'
gives you error because you are not using axios
variable yet. You can ignore rules by:
You can disable a eslint rule on one line by adding // eslint-disable-next-line no-unused-vars
above the line you want to disable, for example:
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
You put your comment in the wrong line, it's supposed to be above import axios from 'axios';
, so change
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
to
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
2. Disabling a rule entirely on your projectYou can also disable a rule entirely on your project. To do this you need to configure your eslint rules in package.json
or .eslintrc.js
depending where you store your eslint configuration.
If you choose to store the eslint configuration in package.json
, add eslintConfig
key like this:
{
"name": "your-app-name",
"dependencies": { ... },
"devDependencies": { ... },
"eslintConfig": { // Add this <-----
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": { // rules configuration here <-----
"no-unused-vars": "off"
}
}
}
If you choose to store eslint config in .eslintrc.js
, simply add rules
key:
module.exports = {
...
rules: {
"no-unused-vars": "off"
}
}
- Read more about ESLint available rules: https://eslint.org/docs/rules/
- Read more about ESLint Rules Configuration: https://eslint.org/docs/user-guide/configuring#configuring-rules
About your edit, the Cannot set property 'render' of undefined
error is caused by the component isn't being exported, this has nothing to do eslint. Change to:
<script>
// eslint-disable-next-line no-unused-vars
import axios from 'axios';
export default {
methods: {
greet() {
alert("Hello!");
}
}
}
</script>
When you are creating a Vue component, you are supposed to export them, read more here: https://v2.vuejs.org/v2/guide/components.html
How to disable warn about some unused params, but keep "@typescript-eslint/no-unused-vars" rule
Only way that I found is to use ignore pattern argsIgnorePattern
in rule options. If your variable is unused, just add underscore _ctx
and ESLint will ignore it, but no-unused-vars
rule will still work for other values. After you will need to use this value, just remove underscore ctx
.
// note you must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
'@typescript-eslint/no-unused-vars': [
'warn', // or error
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
You can change this pattern ^_
as you like using RegExp.
How to disable warnings from @typescript-eslint?
To selectively disable a warning generated by a plugin rule, use the syntax
// eslint-disable-line <plugin>/<rule>
in your case:
handleRecipeDelete: (id) => null, // eslint-disable-line @typescript-eslint/no-unused-vars
I do not know if your approach to creating a context is correct, that is something that you will need to test in your application.
ESLint warning; defined but never used for react-native components
I've finally fixed it here is the solution;
first, install the eslint-plugin-react
and make changes in your .eslintrc.json file.
{
...
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
...
}
Solution source:
https://github.com/babel/babel-eslint/issues/6
Prevent JSHint's " 'a' is defined but never used. " for unused function parameters having following parameters?
As @GOTO0 already commented, you can use
unused:true
to get exactly the wanted behavior.
Source: JSHint Options Reference
Related Topics
Redirect to Url After Form Submit in React
How to Calculate the Sum of Table Column in Angular 2+
How to Get the Ajax Response from Success and Assign It in a Variable Using Jquery
Angular - How to Get Result of a Json Object
How to Pass Data from Flask to JavaScript in a Template
How to Format Numbers by Prepending 0 to Single-Digit Numbers
How to Sort Elements in an Array into Order and Even Numbers and They Should Be in Ascending Order
Add Hyphen After Every Fourth Character in a String Seperated by Comma
How to Find If a Text Contains Url String
Increase Counter Value Upon Button Click
Calculate Total Sum of Dynamically Added Items to a Table
For Loop With Two Array in JavaScript
Regular Expression to Accept Both Positive and Negative Numbers
How to Change Background Opacity When Bootstrap Modal Is Open
How to Change Height in Mat-Form-Field
How to Avoid the Setstate()/Render() Endless Loop When Passing Data from Child to Parent
Typescript - Possible to Disable Type Checking
How to Redirect to Another Page in Reactjs When a If Condition Is Executed