Eslint Error while working with Trails js - javascript

I am using Eslint to lint the code of my Trails.js project before testing it. Tails.js comes with existing pre-configurations eslint-config-trails. However, when I am testing my code eslint throws a Definition for rule 'no-global-assign' was not found error, for every .js file in my codebase.
Manually adding the rule:
"rules": {
"no-global-assign": ["error", {"exceptions": ["Object"]}]
}
Doesn't fix the error. Setting the rule to "warn" makes me at least run the tests, but outputs a warning for every .js file.

The no-global-assign rule was added in ESLint 3.3.0.
You need to use that version or later, if you want to use that rule.

Related

eslint warns about a file being ignored even though I specifically ignored it. Can I disable this?

In my eslintrc.js I have the following ignore patterns:
...
ignorePatterns: [
'bin',
'src/modules/**/*.js',
'test',
'build_util'
],
...
When linting I run this:
eslint src/**/*.js
Everything looks good except I get this warning:
/Users/me/repos/my-project/src/modules/server.js
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
According to the documentation it says:
This message occurs because ESLint is unsure if you wanted to actually lint the file or not.
Uhhh what? How does that make sense? I very specifically told eslint to ignore all js files in that directory. Why is it giving me this warning?
What am I misunderstanding here? How do I turn off warnings like this without turning off all warnings?

Why is this ESLint override file in a create-react-app not finding errors?

I set up a React site with create-react-app and am using VSCode to edit it.
I want to override some of the ESLint rules that it has.
Therefore I installed these packages:
npm i -D eslint-config-airbnb eslint-config-prettier eslint-plugin-jsx-a11y eslint-plugin-prettier prettier
and then created the following .eslintrc file:
However, the rules that I'm adding don't take any effect, e.g. even though I specify that I want to force single quotes and force semi-colons, I have both JavaScript and TypeScript files throughout my application which have single and double quotes, and some lines have semi-colons and some don't, but ESLint in VSCode shows no errors, and I am able to build successfully, and the site builds and publishes without errors at Netlify.
To add to the confusion, only in the .eslintrc file itself does ESLint seem to find errors, yet as you can see above, it finds an error that it shouldn't find: on the rule that states it should only allow single quotes, it says that using single quotes is an error. (!)
What's going on here?
ADDENDUM
I added an .env file with the line EXTEND_ESLINT = "true" and now even though VSCode doesn't find any errors, when I npm start it finds errors in the ServiceWorker.js file in src, although my rule is set to force single quotes ("quotes": ["error", "single"],) and it is saying that the file needs double quotes:
In fact, I see I can remove the quotes rule altogether and having the .env file in my root directory with the line EXTEND_ESLINT = "true" will cause these double quote errors to be generated on a development build.

ESLINT errors ( Error '$' is not defined)

I have Brackets installed, and i getting ESLINT error, as far as i know i dont have ESLINT installed
That is the first time i get this error, my question is, how do i install ESLINT and configure it that i don't receive the errors. ( The JavaScript code is copied from CODEPEN so it should be ok)
The main problem is ESLINt, i tried with other JS plugins and get the same error, as i said its the first time im getting this error.
You need to add the '$' to the globals object inside your .eslintrc file.
Like so:
"eslintConfig": {
"globals": {
"$": true
}
}
You need to configure it to allow globals:
https://eslint.org/docs/user-guide/configuring#specifying-globals
Either comment on top of the file
/* global $ */
or in the config

Prevent "test/expect/etc is not defined" errors when using Jest

Facebook's Jest testing framework is easy to get started with, but the documentation overlooks an annoying aspect: test statements will be highlighted as errors by any editor that tries to warn of undefined symbols, because test, expect, and all matcher methods are not defined.
Similary, attempting to run a test file with node directly will fail with ReferenceError: test is not defined.
What require/import statement(s) need to be added for those errors to go away?
Node
If you want to run them directly through node, try to require jest and/or jest-runtime. Also give #types/jest a try as well.
Check Edit 2 for new info about this
Edit
#types/jest (jest-DefinitelyTyped) is definitely needed (or just one solution). If you install it (e.g., dev dependency), the IDE errors should go away.
I just tried it on Webstorm, and it works.
Edit 2
The new Jest#20 Matchers (e.g., .resolves and .rejects) are still not defined in #types/jest. You can keep track of its status on the links below:
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16645
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16803
It should be available soon, though!
Also, it doesn't seem possible to run it directly through node. Last night I tried a bunch of different things, but using jest is the way to go - it really uses node under the hood, so I thought it would be possible as well. #thymikee over your opened issue at GitHub made clear that it's not.
Edit 3
The new release (20.0.1) includes the newest Jest definitions.
Lint
this isn't in the scope of this specific problem, but it also helps
Are you using something like ESLint? If so, you'll need eslint-plugin-jest
Following the steps described in this page: https://www.npmjs.com/package/eslint-plugin-jest, you will basically need to add it as an ESLint plugin and set jest globals in the ESLint configuration:
{
"env": {
"jest/globals": true
}
}
If you plan on supporting ES6 tests, you'll also need Babel and babel-jest plugin with the following jest configuration:
"transform": {
"^.+\\.js$": "babel-jest"
}
Finally, for Typescript tests you'd need the #types/jest and ts-jest packages as well
Adding following .eslintrc configuration is enough
{"env":
{
"jest": true
}
}
I'm using VSCode and ESLint, you need to install eslint-plugin-jest
Add jest info to your .eslintrc.js
{
"plugins": ["jest"]
},
"env": {
"jest/globals": true
}

Turn off ESLint rule (in React app, using WebStorm)

I am writing a React app in WebStorm using the standard React setup. I have never previously explicitly set up any linting, so whatever error/warning messages are showing up are from some sort of default configuration. When I run npm start I get the following warning:
Compiled with warnings.
Warning in ./path/to/MyComponent.js
/my/complete/path/to/MyComponent.js
19:49 warning Unexpected whitespace before property bind no-whitespace-before-property
...
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
The last two lines make it explicitly clear that the warnings are from ESLint (as opposed to, say, JSHint or some custom React linting, etc.).
I want to keep ESLint running, i.e. I don't just want to globally disable all linting. However, I want to turn the "no-whitespace-before-property" warning off everywhere, not just on one line or in one file. How do I do that?
My package.json shows the following for npm start (which is what I run when the warnings appear):
"scripts": {
"start": "react-scripts start",
...
}
I am developing in WebStorm. The ESLint preferences panel has the "Enable" checkbox unchecked, so all of the ESLint configuration options in the IDE are grayed-out and presumably irrelevant, so presumably also the configuration and invocation of ESLint are happening elsewhere (e.g. built into React?).
I tried putting the following .eslintrc.json file into my project home directory:
{
"rules": {
"no-whitespace-before-property": "off"
}
}
alone as well as with "extends": "eslint:recommended".
I tried adding the following to my project's package.json file:
{
...
"eslintConfig": {
"rules": {
"no-whitespace-before-property": "off"
}
}
}
I've also tried setting the value to 0 instead of to "off".
It may or may not be relevant that I'm writing a React app, and it may or may not be relevant that I'm developing in WebStorm, but I include those facts just in case.
I've checked around on StackOverflow and can't find an answer.
The note below the errors is not coming from ESLint (error is). So I'm assuming you are using some sort of wrapper, like github.com/facebookincubator/create-react-app Those wrappers do not use .eslintrc file and can't be configured directly. You will have to read through documentation of your wrapper to figure out how to disable this rule.
In general ESLint wrappers like create-react-app, standard, xo, etc. are specifically designed to "just work", and hence remove ability to configure and fine tune styles/rules.

Categories

Resources