vscode warn when I use vue3 <script setup> - visual-studio-code

A warning appeared but not tips, how to fix?
I use the vite init project with vue-ts template
only warn but not tips when i hover,and build also success
my eslintrc :
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:vue/essential",
"plugin:#typescript-eslint/recommended",
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: 13,
parser: "#typescript-eslint/parser",
sourceType: "module",
},
plugins: ["vue", "#typescript-eslint"],
rules: {
// indent: ["error", 4],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
semi: ["error", "always"],
},
};
I have installed Vue Language Features (Volar)

Take a look at https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
You have
parserOptions: {
ecmaVersion: 13,
parser: "#typescript-eslint/parser",
sourceType: "module",
}
can you try
parser: "vue-eslint-parser",
parserOptions: {
ecmaVersion: 13,
parser: "#typescript-eslint/parser",
sourceType: "module",
},
You can also check out this repo which has ESLint with TypeScript and Vue set up already and compare your config to the one there: https://github.com/sethidden/vue3-eslint-stylelint-demo

Related

VSCode ESLint Prettier formatOnSave being undone

I'm was trying to resolve some cross-platform issues in our linting (in my case a line-ending issue between Windows and IOs platforms).
Line ending problem is resolved (had to do with a files.eol setting) but when I save my file, some linting is getting reverted, like so
below are my workspace and linting config. What is fighting back at me here?
.eslintrc.js
module.exports = {
root: true,
extends: '#react-native-community',
parser: '#typescript-eslint/parser',
plugins: ['#typescript-eslint', 'unused-imports'],
overrides: [
{
files: ['*.ts', '*.tsx', '*.js'],
rules: {
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
'#typescript-eslint/no-shadow': ['error'],
'no-shadow': 'off',
'no-undef': 'off',
'no-console': 'warn',
'#typescript-eslint/no-unused-vars': 'off',
'react/no-unstable-nested-components': ['warn', {allowAsProps: true}],
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
},
},
],
};
.prettierrc.js
module.exports = {
bracketSpacing: false,
bracketSameLine: true,
singleQuote: true,
trailingComma: "all",
arrowParens: "avoid",
};
myproject.code-workspace
{
"folders": [
{
"path": "."
}
],
"settings": {
"compilerOptions": {
"baseUrl": "",
"paths": {
"lib/*": ["src/lib/*"]
}
},
"editor.formatOnSave": true,
"editor.rulers": [],
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"tailwindCSS.experimental.classRegex": [
"tw`([^`]*)", // tw`...`
"tw=\"([^\"]*)", // <div tw="..." />
"tw={\"([^\"}]*)", // <div tw={"..."} />
"tw\\.\\w+`([^`]*)", // tw.xxx`...`
"tw\\(.*?\\)`([^`]*)" // tw(Component)`...`
],
"eslint.format.enable": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"extensions": {
"recommendations": [
"mikestead.dotenv",
"dsznajder.es7-react-js-snippets",
"eamodio.gitlens",
"dbaeumer.vscode-eslint",
"austenc.tailwind-docs",
"esbenp.prettier-vscode",
"adpyke.codesnap"
]
}
}
Ok problem was the workspace settings editor.formatOnSave and the editor.codeActionsOnSave.
My formatting is handled by the linting so I didn't need the VSCode formatter fighting with the linting.

How to Resolve "Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript'" in Vue SFC

I'm getting this strange error with eslint inside of a Vue SFC template.
Parsing error: This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0) (Which appears to be throwing on the opening tag of the Vue SFC <template> tag.)
Here's the Vue SFC (literally the stock Vite App.vue file)
<template>
<img
alt="Vue logo"
src="./assets/logo.png"
>
<HelloWorld
msg="Hello Vue 3 + Vite"
/>
</template>
Here's my .eslintrc file
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:vue/essential',
'airbnb-base',
],
parser: '#babel/eslint-parser',
parserOptions: {
ecmaVersion: 12,
requireConfigFile: false,
sourceType: 'module',
},
plugins: [
'vue',
],
rules: {
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'vue/no-multiple-template-root': 'off',
},
};
And my package.json in case it's relevant
{
"version": "0.0.0",
"scripts": {
"build": "vite build",
"dev": "vite",
"lint": "eslint **/*.{js,vue}",
"serve": "vite preview"
},
"dependencies": {
"ky": "^0.28.5",
"vue": "^3.0.5"
},
"devDependencies": {
"#babel/core": "^7.15.0",
"#babel/eslint-parser": "^7.15.0",
"#vitejs/plugin-vue": "^1.2.3",
"#vue/compiler-sfc": "^3.0.5",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-vue": "^7.17.0",
"jest": "^27.1.0",
"vite": "^2.3.7"
}
}
I'm not really sure what would cause this since I have
extends: [
'plugin:vue/essential',
'airbnb-base',
],
and
plugins: [
'vue',
],
within .eslintrc.
I'd like to know how to resolve this, but I would also like to understand what's going on here to cause this error to be thrown in the first place.
The issue was being caused by this within .eslintrc
parser: '#babel/eslint-parser',
parserOptions: {
ecmaVersion: 12,
requireConfigFile: false,
sourceType: 'module',
},
It should instead be
parserOptions: {
ecmaVersion: 12,
parser: '#babel/eslint-parser',
requireConfigFile: false,
sourceType: 'module',
},
The parser property isn't even mentioned within https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options so it might just be outdated at this point.

Getting SourceMap position not found for trace with karma-typescript

Getting SourceMap position not found for trace. I am trying to build a unit test framework using typescript, mocha, karma, and karma-typescript and getting the following issue.
I tried using karma-sourcemap-loader but still, there is no luck. Can anyone please guide me on what am I missing here?
karma-typescript should be able to handle these source map things by themself in between multiple transformations.
Fetching /Users/test/sourcecode/test-web-ui/node_modules/karma-typescript/dist/client/commonjs.js
17 08 2021 23:47:06.959:DEBUG [web-server]: serving (cached): /Users/raukumar/sourcecode/test-web-ui/node_modules/karma-typescript/dist/client/commonjs.js
17 08 2021 23:47:07.357:WARN [reporter]: SourceMap position not found for trace: Uncaught Error: Can't find #react/react-spectrum/Button [undefined] (required by /Users/test/sourcecode/elements-web-ui/src/editors/doc/stage/actions/StageActionsView.tsx)
at http://localhost:9882/base/node_modules/karma-typescript/dist/client/commonjs.js?f5014f1e344ba3e2f0d92afe67b92f3001c46c90:13:17
I tried this solution SourceMap position not found for trace: AssertionError (Karma-Typescript) but after this, I am getting some different issues.
Uncaught Error: Can't find #react/react-spectrum/Button [undefined] (required by /Users/test/sourcecode/src/somefile.tsx
Karma.conf
module.exports = (config) => {
config.set({
// basePath: '',
//configFile: join(__dirname, "testing.tsconfig.json"),
plugins: ['karma-chrome-launcher', 'karma-mocha', 'karma-typescript', 'karma-webpack','karma-mocha-reporter','karma-sourcemap-loader'],
frameworks: ['mocha', 'karma-typescript'],
preprocessors: {
"**/*.ts": ["karma-typescript","sourcemap"],
"**/*.tsx": ["karma-typescript","sourcemap"], // *.tsx for React Jsx
'**/*.js': ["sourcemap"]
//"src/**/*.js": ["babel"]
},
logLevel: config.LOG_DEBUG,
browsers: ['Chrome'],
singleRun: true,
autoWatch: false,
color:true,
reporters: ["mocha", "karma-typescript"],
//files: [{ pattern: "src/**/*.ts" }, {pattern: "src/**/*.tsx" }, {pattern: "src/**/*.js"}],
files: [{ pattern: "src/**/!(*.spec).?(ts|tsx)" }, { pattern: "src/**/!(*.integration.spec).?(ts|tsx)" } ],
//webpack: webpackConfig,
karmaTypescriptConfig: {
// Allow tests to run even when there are compiler errors
stopOnFailure: true,
bundlerOptions: {
acornOptions: {
ecmaVersion: 8,
},
transforms: [
// eslint-disable-next-line #typescript-eslint/no-var-requires
require("karma-typescript-es6-transform")({
// eslint-disable-next-line #typescript-eslint/no-var-requires
//presets: [require("#babel/preset-env",{ "useBuiltIns": "entry"})],
//plugins: ['#babel/plugin-transform-spread'],
presets: [
["env", {
targets: {
browsers: ["last 2 Chrome versions"]
}
}]
]
})
]
},
compilerOptions: {
target: "ES2017",
lib: ['DOM', 'ES2015', 'ES2017'],
module: "CommonJS",
// Remove incompatible options
//incremental: false
},
tsconfig: "testing.tsconfig.json"
}
});
}
tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"module": "CommonJS",
"incremental": true,
"noUnusedParameters": false,
"sourceMap": true,
"jsx": "react",
"strict": true,
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*.ts","src/**/*.tsx"],
"exclude": ["node_modules"]
}

Set HTML Before Script Tags in Svelte on VS Code

I am using the Svelte Plugin for vs code: https://marketplace.visualstudio.com/items?itemName=JamesBirtles.svelte-vscode
I also have the eslint and prettier plugins installed:
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
In addition, I have set up .eslintrc.js and .prettierrc files as follows:
// .eslintrc.js
module.exports = {
env: {
browser: true,
es6: true
},
extends: ['prettier'],
overrides: [
{
files: ['**/*.svelte'],
processor: 'svelte3/svelte3'
}
],
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module'
},
plugins: ['prettier', 'svelte3'],
rules: {
'prettier/prettier': 'error',
'svelte3/lint-template': 2
}
}
// .prettierrc
{
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"plugins": [
"svelte"
],
}
Now everything seems to work like it supposed to. But there is one functionality that I would like to change. I would like to have my html on top of the style tags in my .svelte file (and, if possible, also on top of the script tags).
However, when I click on save, it automatically moves all of my html to the bottom of the file.
How can I override this?
Thanks.
prettier-plugin-svelte has a svelteSortOrder option, that can be added to your .prettierrc file.
In your case, it would become:
// .prettierrc
{
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"plugins": [
"svelte"
],
"svelteSortOrder": "scripts-markup-styles"
}

How to disable vscode auto format adding newline at EOF when auto save js files?

I am using vscode and enabled the auto-format config to format files when saving files.
But i recently found that vscode editor always add a newline at EOF of each js file,so how to disable this?
I have specially added the config "files.insertFinalNewline": false, but it still not worked.
vscode info:
Version: 1.33.1 (system setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 6.1.7601
vscode config.json
{
"workbench.colorTheme": "Monokai",
"editor.fontSize": 16,
"editor.formatOnPaste": true,
// Format a file on save.
// A formatter must be available,
// the file must not be auto-saved,
// and editor must not be shutting down.
"editor.formatOnSave": true,
"debug.console.fontSize": 16,
"terminal.integrated.fontSize": 14,
"markdown.preview.fontSize": 14,
"window.zoomLevel": 1,
"editor.renderWhitespace": "all",
"window.title": "${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}",
"search.exclude": {
"**/.gitignore": true,
"**/.idea": true,
"**/.vscode": true,
"**/build": true,
"**/dist": true,
"**/tmp": true,
"**/yarn.lock": true
},
"workbench.iconTheme": "material-icon-theme",
"editor.wordWrapColumn": 110,
"http.proxyStrictSSL": false,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": false,
"files.trimFinalNewlines": false,
"html.format.endWithNewline": false,
"javascript.implicitProjectConfig.experimentalDecorators": true,
// Enable/disable default JavaScript formatter (For Prettier)
"javascript.format.enable": false,
// Use 'prettier-eslint' instead of 'prettier'.
// Other settings will only be fallbacks
// in case they could not be inferred from eslint rules.
"prettier.eslintIntegration": true,
"prettier.tabWidth": 4,
"prettier.singleQuote": true,
"prettier.arrowParens": "always"
}
.eslintrc.json
{
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import",
"react-hooks"
],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"legacyDecorators": true,
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": true,
"es6": true
},
"parser": "babel-eslint",
"globals": {
"describe": true,
"it": true,
"inject": true,
"beforeEach": true,
"addProviders": true,
"spyOn": true,
"expect": true,
"global": true,
"require": true,
"async": true,
"ENVIRONMENT": true,
"client": true
},
"rules": {
"linebreak-style": 0,
"quotes": [2, "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}],
"indent": [2, 4, {
"SwitchCase": 1,
"VariableDeclarator": 1
}],
"react/jsx-indent": [2, 4],
"comma-dangle": ["error", "never"],
"class-methods-use-this": 0,
"import/newline-after-import": 0,
"space-before-function-paren": ["error", "never"],
"func-names": ["error", "never"],
"consistent-return": [0],
"eol-last": ["error", "never"],
"no-script-url": ["off"],
"react/jsx-indent-props": [2, 4],
"react/forbid-prop-types": [2, {
"forbid": []
}],
"jsx-a11y/anchor-is-valid": ["error", {
"components": ["Link"],
"specialLink": ["to"],
"aspects": ["noHref"]
}],
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/click-events-have-key-events": "off",
"import/no-unresolved": [
"error",
{
"ignore": ["client/"]
}
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"import/extensions": 0,
"max-len": [
0, 110, 4
],
"react/jsx-filename-extension": [
1,
{
"extensions": [
".js",
".jsx"
]
}
],
"react-hooks/rules-of-hooks": "error"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".json", ".css"]
}
}
}
}
So, how to config vscode correctly?
I had the same problem. To fix it you need to be in the folder of your project. then open your settings i.e command + shift + p, type settings, select Preferences: open settings UI, under Text Editor tab, choose Files and you'll find Eol tab to choose from \n, \n, auto. I choose auto so it will override whatever you specify.