eslint: Parsing error: Unexpected character '#', in .scss - eslint

This is a scss file, Why does this happen?
eslint tips:
Parsing error: Unexpected character '#'

Because eslint is trying to lint a SCSS file.
You need to exclude SCSS type files. Edit your package.json like below:
{
...
"eslintIgnore" : ["**/*.scss"],
...
}

You can enables or disables all scss validations in the settings like so:
"scss.validate": false
Customizing CSS, SCSS and Less Settings

Related

.eslintrc.js 'module' is not defined

I'm getting 'module' is not defined error from the eslint in .eslintrc.js file.
What does this mean and how do I fix it?
You need to add an environment setting inside your .eslintrc.js file, i.e.:
...
env: {
node: true
},
...
That said, the error in the .eslintrc.js file itself should only appear in Visual Studio Code, because ESLint ignores file names that start with a dot per default.
convert to es5 by writing export default { } instead of module.export = {}

eslint error: 'Uint32Array' is not defined. no-undef

When using Uint32Array with TypeScript and eslint, I to this error.
34:43 error 'Uint32Array' is not defined no-undef
How do I fix this?
My eslintrc looks like this (YAML syntax used):
env:
browser: true
jasmine: true
jest:
You need to add "es6": true to you .eslintrc file. This tells eslint to consume the "builtin" globals that the browser JS engine provides.

how to silence warnings about ignored files in eslint

After setting up eslint and adding some files in the ignore list, every time that eslint is run it produces warnings about files that are ignored:
/path/to/file/name.min.js
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
How can this warning be silenced?
One workaround I know at the moment is --quiet option, which suppresses all warnings. Of course that doesn't make sense if you have "warn" rules in your config.
Another way not to show that warning is to use dir names: eslint src instead of globbing patterns: eslint src/*.
Check if you're running eslint with an unquoted glob argument.
If so, put the glob in quotes.
eslint src/** ❌ Bad (no quotes = OS will expand into many args)
eslint "src/**" ✔️ Good (quotes = a single string argument)
Why?
If you call eslint using a cli glob pattern not in quotes, e.g. eslint src/**, that glob gets expanded into all matching files and passed to eslint as a gigantic list of cli arguments. e.g. eslint path/to/file/name.min.js src/foo.js src/bar.js src/manymore.js .....
So when eslint ignores a file due to your ignore pattern, yet that file was explicitly passed as a command line argument, eslint is warning us
eslint speaking:
"Um, I ignored /path/to/file/name.min.js because of an ignore pattern, but you explicitly passed it to me to lint, so this must not be what you wanted, right?"
But when you pass the glob in quotes, e.g. eslint "src/**", the glob is not expanded to many arguments; rather, it's just a single string argument, and eslint is the one who knows it's a glob but since it takes care of figuring out which files to match it can do so while respecting eslintignore. So there's nothing weird going on that eslint thinks it should warn you about.
You can't and they don't plan on fixing it since they don't consider it a bug. So if you pass in a file that's being ignored them it will tell you it didn't process linting rules because it's ignored: https://github.com/eslint/eslint/issues/5623
We run pre-commit hooks to lint code before committing, so ended up needing to write some additional code to differentiate between actual Warnings and File ignored warnings and only fail linting if an actual warning or error is thrown.
The solution for Lint Staged & Husky errors
// lint-staged.config.js
const { ESLint } = require("eslint");
const removeIgnoredFiles = async (files) => {
const eslint = new ESLint();
const ignoredFiles = await Promise.all(files.map((file) => eslint.isPathIgnored(file)));
const filteredFiles = files.filter((_, i) => !ignoredFiles[i]);
return filteredFiles.join(" ");
};
module.exports = {
"*.{js,ts}": async (files) => {
const filesToLint = await removeIgnoredFiles(files);
return [`eslint --max-warnings=0 ${filesToLint}`];
},
};
If the file is ignored by ESLint (i.e. in .eslintignore), this snippet filters the file and does not pass it through the ESLint CLI.
ref: Testing Library - Aug 2022
I found the REAL answer here:
https://github.com/eslint/eslint/issues/5623
The problem in my case was in the way I called eslint. I used eslint src/* but it should be eslint src/. (Or in your case it might be eslint . instead of eslint *)
The reason why you get the warning is that by using the star, you are telling the eslint that you want to lint EVERY single file which does not make sense if you ignore some files. So by omiting the star you are making the eslint to decide what to lint and it will skip the ignored files without any warning.
Eslint throws this warning on telling it to lint a file, at the same time as having the file ignored. src/* is actually passing every file single file uniquely, while only passing src would let eslint ignore the files without warnings
If you are using lint-staged, it will pass every single staged file that matches the lint-staged regex. If matching, and you put it inside ignore, eslint gets confused and outputs a warning
"lint-staged": {
"*.{ts,tsx,js}": [ // <-- this regex needs to be changed to not match your files
"eslint --fix --max-warnings 0 --ignore-path '.eslintignore' --plugin tsc --rule 'tsc/config: [2, {configFile: \"./tsconfig.json\"}]'",
"prettier --ignore-path .eslintignore --write"
],
"*.js": "eslint --cache --fix",
"*.{js,css,md}": "prettier --write"
},
For me, I just wanted to exclude some js files, so I just removed the js matching inside "*.{ts,tsx,js}"
try with --ext. In my case, I replaced matching from:
eslint modules/**/*{js,vue}
to:
eslint --ext .js,.vue .
Warnings with File ignored because... are gone, but others warnings remain.
My solution for Next.js next lint and a .lintstagedrc.js file. This removes the files that have that warning from the final string of files to lint.
// .lintstagedrc.js
const path = require("path");
const ignorePaths = ["types/global.d.ts", ".lintstagedrc.js"];
const buildEslintCommand = (filenames) => {
return `next lint --fix --max-warnings=0 --file ${filenames
.reduce((files, file) => {
const pathToFile = path.relative(process.cwd(), file);
if (!ignorePaths.includes(pathToFile)) files.push(pathToFile);
return files;
}, [])
.join(" --file ")}`;
};
module.exports = {
"*.{ts,tsx,js,jsx}": [buildEslintCommand],
"*.{ts,tsx,js,jsx,css,scss,md}": "prettier --write",
};

JSHint: Turn off missing semicolon warning

How do I turn off missing semicolon warnings with JSHint in Sublime? I have tried multiple things on the internet to no avail.
asi is an option within the sublime linter that will suppress the semicolon warnings when set to true.
See JSHint Info
For additional information.
Ultimately, you'll want to create a .jshintrc file in your app root folder and add the following code inside:
{
"asi": true,
}
Set the file type as json, save it and restart your ide.
By inserting the following line at the beginning of your .js Javascript file should work:
/*jshint -W033 */

How can I use the require-js text-plugin with karma

I am trying to get the require-js text plugin to work with the karma-testrunner
I downloaded both with npm. I got karma working with requirejs, it is only the text-plugin that is making me some trouble.
When I add the text.js file to the files that karma serves I get a mismatch Error for it:
Uncaught Error: Mismatched anonymous define() module: function (module) {
//code from text plugin
If I don't serve the file with the text-plugin or exclude in karma.conf it I get a script Error from requirejs
(and a karma Warning: 404/base/text.js)
Uncaught Error: Script error for: text
I added the following to my require config file:
require.config({
paths: {
text: './text.js' //also tried text.js
}
})
but that doesn't seem to change anything
I have the dependency on the text plugin and template declared like this:
define(['text!views/viewtemplate.html'], function (template) { ...
I was having this issue, too, as I was trying to bring mock JSON files into my test files and parse them with JSON.parse(requirejsInjectedJsonText).
The issue I had was forgetting to update my karma config file with the require-js-text and mock files:
files: [
{pattern: 'mocks/**/*.json', included: false},
{pattern:'lib/requirejs-text/text.js', included: false},
'config/require.config.js'
]
After adding these in place (requirejs config reference must always be in the last index of 'files' array in the karma config file), I was able to successfully pull in my mock data.
For the record, as I was fiddling around, I went as far as #ddd in adding the shim to the require config, i.e.:
shim: {
'text': {'exports': 'text'}
}
But, it turned out to be unnecessary after I removed it AND had the karma config setup as above.
Cheers!

Resources