<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Visaka Devi Chaves</title>
    <description>The latest articles on DEV Community by Visaka Devi Chaves (@devidev).</description>
    <link>https://dev.to/devidev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2299251%2F01978ed9-09c7-446d-b3ee-9153bc70cffb.png</url>
      <title>DEV Community: Visaka Devi Chaves</title>
      <link>https://dev.to/devidev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devidev"/>
    <language>en</language>
    <item>
      <title>Vue3 + ESLint 9.13.0 + Prettier +TypeScript and VSCode Autoformat on Save</title>
      <dc:creator>Visaka Devi Chaves</dc:creator>
      <pubDate>Tue, 05 Nov 2024 16:50:44 +0000</pubDate>
      <link>https://dev.to/devidev/setting-up-eslint-9130-with-prettier-typescript-vuejs-and-vscode-autosave-autoformat-n0</link>
      <guid>https://dev.to/devidev/setting-up-eslint-9130-with-prettier-typescript-vuejs-and-vscode-autosave-autoformat-n0</guid>
      <description>&lt;p&gt;This guide will walk you through configuring a Vue.js project with ESLint 9.13.0, Prettier, and TypeScript, to enable automatic code formatting and linting on save in Visual Studio Code.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Create a New Vue Project
&lt;/h3&gt;

&lt;p&gt;Start by creating a new Vue project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vue@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate into the project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;your-project-directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Install and Update Dependencies
&lt;/h3&gt;

&lt;p&gt;Install the project dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, use &lt;code&gt;ncu&lt;/code&gt; (Node Check Updates) to update the project dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx ncu &lt;span class="nt"&gt;-u&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Prerequisites Add ESLint, Prettier, and TypeScript Packages
&lt;/h3&gt;

&lt;p&gt;This configuration requires the following NPM packages to be installed either locally or globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prettier
eslint prettier-eslint
@typescript-eslint/parser
typescript 
vue-eslint-parser
@vue/eslint-config-typescript 
@vue/eslint-config-prettier

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the necessary development dependencies with &lt;code&gt;pnpm&lt;/code&gt; or &lt;code&gt;npm&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; prettier eslint prettier-eslint @typescript-eslint/parser typescript vue-eslint-parser @vue/eslint-config-typescript @vue/eslint-config-prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Initialize ESLint Configuration
&lt;/h3&gt;

&lt;p&gt;Run the following command to set up your ESLint configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init @eslint/config@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompted, make the following selections to configure ESLint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How would you like to use ESLint?&lt;/strong&gt;: To check syntax and find problems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What type of modules does your project use?&lt;/strong&gt;: CommonJS (require/exports).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Which framework does your project use?&lt;/strong&gt;: Vue.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Does your project use TypeScript?&lt;/strong&gt;: Yes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where does your code run?&lt;/strong&gt;: Browser.&lt;/li&gt;
&lt;li&gt;When asked if you'd like to install dependencies (&lt;code&gt;eslint&lt;/code&gt;, &lt;code&gt;globals&lt;/code&gt;, &lt;code&gt;@eslint/js&lt;/code&gt;, &lt;code&gt;@typescript-eslint&lt;/code&gt;, &lt;code&gt;eslint-plugin-vue&lt;/code&gt;), choose &lt;strong&gt;Yes&lt;/strong&gt; and use &lt;strong&gt;npm&lt;/strong&gt;  or your preferred package manager.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Add ESLint Flat Config
&lt;/h3&gt;

&lt;p&gt;To ensure ESLint works with the new Flat Config format, make sure to include the necessary configuration in your &lt;code&gt;eslint.config.mjs&lt;/code&gt; file. Adjustments for this might depend on your specific setup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// eslint.config.mjs

import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import pluginVue from 'eslint-plugin-vue';
import prettier from 'eslint-plugin-prettier/recommended';
import vueConfigTypescript from '@vue/eslint-config-typescript';
import vueConfigPrettier from '@vue/eslint-config-prettier';

/** @type {import('eslint').Linter.Config[]} */
export default [
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
      },
    },
  },
  // js
  pluginJs.configs.recommended,
  {
    rules: {
      'no-unused-vars': 'off',
      'no-undef': 'off',
    },
  },
  // ts
  ...tseslint.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-unused-vars': 'warn',
      '@typescript-eslint/no-explicit-any': 'warn',
    },
  },
  // vue
  ...pluginVue.configs['flat/recommended'],
  {
    files: ['*.vue', '**/*.vue'],
    languageOptions: {
      parserOptions: {
        parser: tseslint.parser,
      },
    },
  },
  {
    rules: {
      ...vueConfigTypescript.rules,
      ...vueConfigPrettier.rules,
      'prettier/prettier': [
        'warn',
        {
          singleQuote: true,
        },
      ],
      'vue/multi-word-component-names': 'off',
      'vue/attribute-hyphenation': 'off',
      'vue/no-v-html': 'off',
      'vue/v-on-event-hyphenation': 'off',
      '@typescript-eslint/ban-ts-comment': 'off',
      '@typescript-eslint/no-require-imports': 'off',
      '@typescript-eslint/no-explicit-any': 'off',
    },
  },
  {
    ignores: ['node_modules', '.nuxt', '.output', 'dist'],
  },
  // prettier
  prettier,
  {
    rules: {
      'prettier/prettier': ['warn', { singleQuote: true }],
    },
  },
];

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Install VSCode Extension for Prettier-ESLint Integration
&lt;/h3&gt;

&lt;p&gt;To enable auto-formatting on save with Prettier and ESLint, install the following Visual Studio Code extension:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prettier ESLint&lt;/strong&gt;: &lt;a href="https://marketplace.visualstudio.com/items?itemName=rvest.vs-code-prettier-eslint" rel="noopener noreferrer"&gt;Download here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. Add Extension Recommendations
&lt;/h3&gt;

&lt;p&gt;To recommend the extension for your project, add it to the &lt;code&gt;.vscode/extensions.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"recommendations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"rvest.vs-code-prettier-eslint"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. Restart VSCode
&lt;/h3&gt;

&lt;p&gt;After configuring your project and installing the extension, restart Visual Studio Code to ensure that autosave and autoformat work as expected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Your project should now be set up with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ESLint 9.13.0 with TypeScript and Vue.js support&lt;/li&gt;
&lt;li&gt;Prettier integration for consistent code formatting&lt;/li&gt;
&lt;li&gt;Autoformatting on save in VSCode using the Prettier ESLint extension
ESLint Flat Config&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>eslint</category>
      <category>prettier</category>
    </item>
  </channel>
</rss>
