I created a new nuxt app using npx create-nuxt-app <project-name> and chose to use eslint and prettier.
I opened the project's directory using vscode and installed the ESLint and Prettier - Code formatter, and Vetur extensions.
When I save a .vue file vscode formats the code, but in a way that breaks the settings in the nuxt project.
For example vscode transforms
<div
class="test"
style="background: red">
test
</div>
to
<div class="test" style="background: red">test</div>
but this breaks the vue/max-attributes-per-line rule.
How do I set up vscode to use the nuxt project's linting and prettyfying rules?
When starting a new nuxt project using npx create-nuxt-app, check both ESLint and Prettier for linting options and choose the recommended jsconfig.json option.
Then do the following:
install additional npm dev packages
npm install --save-dev babel-eslint eslint eslint-config-prettier eslint-loader eslint-plugin-vue eslint-plugin-prettier prettier
Install VS Code extensions
Prettier
ESLint
Vetur
Formatting Toggle (optional)
Change your workplace settings (.vscode/settings.json) to the following:
{
"eslint.format.enable": true,
"vetur.format.defaultFormatter.html": "prettier"
}
You can toggle auto fixing using the Formatting Toggle extension, or if you didn't install it by changing your user settings:
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true
}
Change your .prettierrc file (optional)
{
"semi": false,
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"endOfLine": "lf"
}
Install the extensions:
Vue
Vue 2 Snippets
Vue Peek
Vetur
ESLint
Go to File > Preferences > Settings and edit the User Settings file, adding the following configuration:
{
...... ,
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
{
"language": "vue",
"autoFix": true
},
{
"language": "html",
"autoFix": true
},
{
"language": "javascript",
"autoFix": true
}
],
}
With this configuration, VSCode will perform validation for these three file types: vue, HTML and JavaScript. Now go back to the src/App.vue file and press ctrl+alt+f on Windows or ctrl+shift+i on Linux or ctrl+options+f on Mac OS to perform the formatting of the code. ESLint will validate the code and display some errors on the screen.
Any errors can be corrected automatically, and it’s not necessary to correct each error manually. To do this, you can
press
ctrl+shift+p
and select
ESLint: Fix all problems
Related
We are using Visual Studio Code to develop a react native project using Tailwind CSS with this npm package: https://www.npmjs.com/package/twrnc. We had installed Prettier in our vscode and postcss, prettier, prettier-plugin-tailwindcss in our package.json's devDependencies section.
The auto complete function work fine but the auto sorting cannot work.
twrnc with style class Attribute not working
But when we switch the style keyword to class, it works.twrnc with class class Attribute work
We try to follow the config setting suggestion here: https://github.com/tailwindlabs/tailwindcss/issues/7553#issuecomment-735915659
Here is our VSCode setting json:
"editor.formatOnSave": true,
"tailwindCSS.classAttributes": ["class", "className", "ngClass", "style"],
"scss.validate": false,
"editor.quickSuggestions": {
"strings": true
},
"editor.autoClosingQuotes": "always",
"tailwindCSS.experimental.classRegex": [
"tw`([^`]*)", // tw`...`
"tw=\"([^\"]*)", // <div tw="..." />
"tw={\"([^\"}]*)", // <div tw={"..."} />
"tw\\.\\w+`([^`]*)", // tw.xxx`...`
"tw\\(.*?\\)`([^`]*)" // tw(Component)`...`
],
"tailwindCSS.includeLanguages": {
"typescript": "javascript",
"typescriptreact": "javascript"
}
Can anyone give me some suggesion on how to fix it? Many Thanks.
I'm trying to upload a basic nuxt.js project with tailwind.css 2.0.
I used :
yarn add --dev tailwindcss#npm:#tailwindcss/postcss7-compat postcss#^7 autoprefixer#^9
to install tailwindcss 2.0
First I was using npm then yarn but on deployment tailwindcss 2.0 doesn't work.
On local it works great.
I can't really tell without more details, but if you are encountering difficulties in production but not in development for a tailwindcss project - the first thing to check is whether you are using dynamic class names (for example, text-${color}-500). These will be purged in production unless you add them to the allowlist.
UPDATE
Having taken a look at the repo you have provided, it looks like the issue is that Tailwind generates CSS targeting [type='text'] but this is purged by html-minifier in the generated HTML of your Nuxt app (see issue). You can turn off this behaviour with this code in your nuxt.config:
export default {
build: {
html: {
minify: {
collapseBooleanAttributes: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeEmptyAttributes: true,
// this is the only line we're changing from defaults
// but we have to include all as they aren't merged
removeRedundantAttributes: false,
trimCustomFragments: true,
useShortDoctype: true
}
}
}
}
I can't figure out how to set the configuration in for the space between function parentheses. I've set it everywhere to true, but when I save a .vue file, the space is removed - after it is removed it is highlighted as error (Missing space between function parentheses). It happens in script section. In .js files spaces are added, but also highlighted as error, this time... Unexpected space between function parentheses?! There was some configuration of settings (which I'm not able to recreate now) when on save the space was added for a moment and then removed again in .vue files.
my settings.json
"vetur.format.defaultFormatter.js": "prettier", // tried both prettier and typescript
// "vetur.format.defaultFormatter.js": "vscode-typescript", // tried both prettier and typescript
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format.insertSpaceBeforeFunctionParenthesis": true,
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true,
"spaceBeforeFunctionParen": true,
"eslintIntegration": true,
},
"vscode-typescript": {
"singleQuote": true,
"spaceBeforeFunctionParen": true,
"eslintIntegration": true,
}
},
.eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'#vue/standard'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
"space-before-function-paren": ["error", "always"], //setting this to 'never' removes the error highlight in vue files, not js files
},
parserOptions: {
parser: 'babel-eslint',
sourceType: "module"
}
}
I've read a zillion questions and set the space-between-function-parentheses in every possible setting that I found in the answers. Still the linting process finds a way to ignore all those settings and implement a different one. Not to mention that it highlights errors not consistent with the auto-formatting. Is there any other setting that I am still missing?
Try this:
npm install prettier#v1.19.1 --save-dev --save-exact
and then restart VS Code.
Prettier just recently updated to v2 and if your project doesn't have prettier installed locally it will use VS Code's version, which is most probably the latest version. In prettier v2 the space-before-function-paren has become a default and hence will be applied on all your projects that don't have a local version of prettier pre v2 installed. For me using any config combination didn't seem to work - it's like prettier just ignored all of them. Hope this helps.
Prior to Prettier v2, It seems to not support space-before-function-paren rule. So We should turn off the rule above to resolve conflict.
Try this
module.exports = {
rules: {
'space-before-function-paren': 'off'
}
}
in an ESLint configuration file(such as .eslintrc.js) located in root directory of project.
Then we should add following to settings.json in VS Code.
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
Last but not least, Disabling Vetur extension in VS Code might be a better choice.
I also had same exact issue with vetur and ESLint extns. Following in settings.json fixed it. By default it was prettier.
"vetur.format.defaultFormatter.js": "prettier-eslint",
I would like to dismiss this error on my vue file
I am trying to add this processor line
<!-- eslint-disable-next-line vue/no-use-v-if-with-v-for -->
and
<!-- eslint-disable-next-line vue/no-confusing-v-for-v-if -->
but neither
Nor
dismiss the eslint warning
[eslint-plugin-vue] [vue/no-use-v-if-with-v-for]
The 'value' variable inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.
I'm using the vetur extension for VSCode.
I added the precessor line fallowing this sample but eslint still warns about the next line.
PS. This solution is not the best one, but I needed it like this due the transition animation.
See Vetur's documentation:
Install ESLint plugin for the best linting experience. Vetur's template linting is only for quick start and does not support rule configuration.
So, you have to:
Install ESLint plugin
Enable vue plugin and disable Vetur's linting (add to VS Code config):
"vetur.validation.template": false,
"eslint.validate": [
"javascript",
"javascriptreact",
"vue"
]
If you don't have eslint and/or eslint-plugin-vue already installed, you should do that:
npm i eslint babel-eslint eslint-plugin-vue --save-dev
Simple config for ESLint:
{
"root": true,
"env": {
"node": true
},
"extends": ["plugin:vue/essential", "eslint:recommended"],
"rules": {
},
"parserOptions": {
"parser": "babel-eslint"
}
}
You should save it either to .eslintrc file or to package.json under eslintConfig name.
And, it works:
If you really want to disable it, try the solution below (it works for me). Since you are specific about the rule it doesn't disable other warnings:
<!-- eslint-disable vue/no-v-html -->
<textarea
type="email"
name="message"
required
aria-required="true"
v-html="form.inputs.name.placeholder"
/>
<!-- eslint-enable -->
Try {{! template-lint-disable }}
I have followed the steps outlined in the VS Code documentation for getting Intellisense working for React Native by installing typings for React Native. Now, what do I need to do to get autocomplete working? For instance, if I type <Text>, I would like to see an automatic closing of that tag. What am I missing here? This seems like it shuld work out of the box.
To enable IntelliSense (autocomplete) you have to install the official React Native Tools extension.
Installation
Open Command Palette by pressing F1, type ext install and press Enter, then look for React Native Tools extension.
Create a jsconfig.json file
You should create a jsconfig.json file in you root directory. It can be empty but must be present. The presence of such a file in a directory indicates that the directory is the root of a JavaScript project.
(Optional)
The file itself can optionally list the files belonging to the project, the files to be excluded from the project, as well as compiler options.
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
]
}
You can find more at https://code.visualstudio.com/docs/languages/javascript#_javascript-projects-jsconfigjson
Create a .babelrc file for ReactNative Packger transformer (optional, if you want to use TypeScript)
You should create a .babelrc file with sourceMaps = true and "presets": [ "react-native" ] for better source-mapping support. (required if you want TypeScript support).
{
"presets": [
"react-native" // this is required for debugging with react-native/packager/transformer
],
"plugins": [],
"sourceMaps": true // must be true react-native/packager/transformer using with node-module-debug
// because of some bugs from vscode-node-debug & vscode-react-native, "sourceMaps" cannot be "inline" or "both"
}
Install typings for React Native (optional)
To get IntelliSense for React Native, run npm install typings -g and then typings install dt~react-native --global in your terminal.
Hope this helps!!
React Native Tools in VSCode can't help you close the Tag after you typed<Text>,you can try to install Auto Close Tag and Auto Rename Tag
In my case, I have to copy jsconfig.json to tsconfig.json, close Visual Code and reopen it. Then it works properly.
jsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
]
}
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
]
}
I am also not getting any IntelliSense and also package auto-import is not working. Since I am not using Typescript, deleting the tsconfig.json helped me.
Take backup of your tsconfig.json file first
In my case, I've already installed many react-native extensions for autoSuggestion and another helper extension, e.g. "React Native Tools", and "React-Native/React/Redux snippets for es6/es7"
Issues:
autoSuggestion keywords not coming while typing.
command(in IOS) + click not letting me to jump on the target files.
Recently I have seen in VS Code editor for new React-native applications autoSuggestion not working.
Steps I have followed to solve:
Go to Extensions
Search for React or React-native
Remove the installed extension
Reload it.