I created a NextJs project and I wanted to integrate Prettier ans Eslint to help me out.
Here's my config files:
.prettierrc
{
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"endOfLine": "auto"
}
.eslintrc
{
"plugins": ["prettier"],
"extends": ["prettier"],
"rules": {
"prettier/prettier": "error"
},
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
}
}
}
I also have a .editor config file
# EditorConfig is awesome: http://EditorConfig.org
2
3 # top-most EditorConfig file
4 root = true
5
6 # Unix-style newlines with a newline ending every file
7 [*]
8 end_of_line = lf
9 insert_final_newline = true
10 indent_style = space
11 indent_size = 4
12 charset = utf-8
13
14 [*.{js,json}]
15 indent_size = 2
16
17 [*.sql]
18 indent_size = 8
When save my files, I get the error
prettier/prettier: Delete `··`
Can someone help me out?
there is a conflict between .prettierrc and .editorconfig. ESLint will only follow what is in the .prettierrc. In your case, your file is following .editorconfig rule (that overwrites what is in .prettierrc) but your ESLint is following .prettierrc rule.
in your .prettierrc,
"tabWidth": 2
in your .editorconfig,
indent_size = 4
you can either set "tabWidth": 4 or remove indent_size = 4 to resolve the problem (depends on whether you prefer 2 or 4).
in fact these parameters in .editorconfig
end_of_line
indent_style
indent_size/tab_width
max_line_length
will conflict with these in .prettierrc
"endOfLine"
"useTabs"
"tabWidth"
"printWidth"
you can either let .editorconfig to follow .prettierrc default or sync both .editorconfig and .prettierrc for things to work properly.
Related
I use eslint to lint, but it does not automatically fix although I use --fix
PS C:\Users\issac\IdeaProjects\discord-bot> eslint --fix --ext .ts src
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
C:\Users\issac\IdeaProjects\discord-bot\src\bot.ts
16:1 error Expected indentation of 4 spaces but found 2 indent
17:1 error Expected indentation of 8 spaces but found 4 indent
18:1 error Expected indentation of 12 spaces but found 6 indent
19:1 error Expected indentation of 16 spaces but found 8 indent
... all most errors indent
75:1 error Expected indentation of 12 spaces but found 6 indent
76:1 error Expected indentation of 12 spaces but found 6 indent
76:34 error Unexpected use of '<<' no-bitwise
77:1 error Expected indentation of 8 spaces but found 4 indent
✖ 862 problems (852 errors, 10 warnings)
790 errors and 0 warnings potentially fixable with the `--fix` option.
Although I run with --fix every time, those errors won't disappear.
This is my .eslintrc.js
module.exports = {
root: true,
env: {
es2021: true,
node: true,
},
parser: '#typescript-eslint/parser',
plugins: [
'#typescript-eslint',
],
extends: [
'airbnb',
'airbnb-typescript'
],
parserOptions: {
ecmaVersion: 13,
project: './tsconfig.json',
sourceType: 'module',
},
rules: {
'max-len': [1, 150, 4],
'object-curly-spacing': [2, 'always'],
'require-jsdoc': [0],
'indent': [2, 4],
'linebreak-style': [0],
'keyword-spacing': [2],
},
overrides: [
{
"files": ["*.ts"],
rules: {
"#typescript-eslint/explicit-function-return-type": ["error"]
}
}
]
};
Is there any way to make eslint fix those all indents?
I have the following lint config...
{
"extends": ["eslint:recommended", "google"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"require-jsdoc": 1
},
"env": {
"es6": true
}
}
and the following code...
const __dirname = path.dirname(new URL(import.meta.url).pathname);
//^Error is...
But when it lints I get...
9:46 error Parsing error: Unexpected token .
This is a pretty common piece of code so I am confused.
Update
solved with...
"ignorePatterns": ["unclean.mjs", "node_modules"],
But I would like a solution where I don't have to ignore an entire file.
It is a syntax error because the default parser of ESLint only supports stage 4 proposals, but import.meta is currently stage 3. For now, you must change the parser to "babel-eslint" or "#typescript-eslint/parser" in order to parse import.meta.
That phrase is a syntax error because import is a keyword in EcmaScript. Therefore import.meta is as invalid as if.foo or switch.foo.
OS: macOS Sierra 10.12.5 .
Sublime Text: Build 3126 .
jshint v2.9.5 .
eslint v4.4.0 .
I have installed below packages for linting the js file
sublimeLinter-contrib-eslint
sublimeLinter-jshint
In my each .js file, IIFE (function(){ has been written on the top of the file BUT linter gives below error in gutter
Incompatible values for "undefined" and "undefined" linting options.
I have both .jshintrc and .eslintrc file in my project root directory BUT I am a bit confused
1. Which linter throw this error? and
2. How to resolve/fix it?
-.jshintrc_
{
"node": true,
"esversion": 6,
"globals" : {
"moment": true,
"saveAs": true
}
}
.eslintrc
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"globals": {
"angular": true,
"module": true,
"inject": true,
"moment": true,
"saveAs": true,
"AWS": true,
"require": false
},
"rules": {
"indent": [0,"tab"],
"linebreak-style": [0, "unix"],
"semi": [2, "always"]
}
}
JS file
(function() {
'use strict';
angular.module().controller(function () { //....code.... });
})();
I have tried the rules as per eslint documentation
"rules": {
"wrap-iife": [2, "outside"]
}
tried all possible values but did not succeed.
Found solution by using Debug mode for sublimeLinter.
there are mixing of 2 .jshintrc files. one is the default ( which can be viewed by (context menu > JSHint > Set Linting Preferences ) and other is custom .jshintrc which located in my project root directory and also there are 2 property esnext and esversion written which I think is not valid. from this refrence
so first clear all comments from default .jshintrc (/Users//Library/Application Support/Sublime Text 3/Packages/JSHint Gutter/.jshintrc) and remove esversion property from custom .jshintrc file and everything is working fine now.
I'm using the eslint 3.18.0 and node 7.7.4. I'm setting the ecmaVersion to 8 (per the documentation), but getting this error: Parsing error: ecmaVersion must be 3, 5, 6, or 7. Is ecmaVersion 8 not supported? If it is why am I getting this parsing error?
Here's the full .eslintrc.json:
{
"env": {
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"]
}
}
ESLint currently supports versions 3, 5, 6 (es2015), 7(es2016) and 8(es2017). If you are having trouble enabling es2017, verify that your ESLint installation is up to date. es2017 was added to ESLint as of v3.6.0 that was released on Sep 23, 2016. Verify global/local version (whichever you are using).
The ecmaVersion is not valid; I recently installed eslint and ecamVersion was set to 13
"parserOptions": {
"ecmaVersion": 13
},
The valid versions are 3 to 12 or latest. I use 'latest' :)
I solved this by doing the following
Deleted the node-modules directory & package-lock.json
npm install
Changed the ecmaScript version in .eslint file
It worked for me.
I'm consistently getting wrong line numbers on the eslint output:
$ ./node_modules/.bin/rollup -c
/Users/asko/Git/es6-trial/src/main.js
31:7 error Expected indentation of 4 space characters but found 6 indent
60:7 error Expected indentation of 4 space characters but found 6 indent
61:7 error Expected indentation of 4 space characters but found 6 indent
134:7 error Expected indentation of 4 space characters but found 6 indent
142:9 error Expected indentation of 6 space characters but found 8 indent
✖ 5 problems (5 errors, 0 warnings)
The reported numbers are one larger than where the problems actually are.
But if I edit the file, the eslint output does not change! Is it doing caching of some type?
Unfortunately, the repo where this originates from is not public.
.eslintrs.json is:
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"env": {
"browser": true,
"es6": true
},
"globals": {
"assert": false
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
// "quotes": ["warn", "single"],
"semi": ["error", "always"],
"no-console": "off",
"no-unused-vars": "warn"
}
}
All of this is weird. Has anyone else, ever, seen this?
It has to do with running eslint via Rollup. If I run things directly with ./node_modules/.bin/eslint src/*.js, there is nothing to report.
Ensure that the eslint plugin is configured before the babel plugin otherwise linting will run on transpiled code, e.g.:
plugins: [
eslint({
exclude: 'node_modules/**'
}),
babel({
exclude: 'node_modules/**'
})
]
instead of
plugins: [
babel({
exclude: 'node_modules/**'
}),
eslint({
exclude: 'node_modules/**'
})
]
See https://github.com/TrySound/rollup-plugin-eslint/issues/10