Help us understand the problem. What is going on with this article?

Sapper ( Svelte ) の Lint / Prettier の設定を 📝

はじめに

Sapper プロジェクト作るたびに Lint の設定に時間を取られるのでメモしておきます。
(個人的なメモレベルなので変なところあったら教えてもらえると助かります!)

ESLint

Install

$ npm install \
  eslint \
  eslint-plugin-import \
  eslint-plugin-node \
  eslint-plugin-promise \
  eslint-plugin-standard \
  eslint-plugin-svelte3 \
  --save-dev

Settings

  • .eslintrc.js
  • .eslintignore
.eslintrc.js
module.exports = {
  parserOptions: {
    ecmaVersion: 2019,
    sourceType: 'module'
  },
  env: {
    es6: true,
    browser: true,
    node: true
  },
  extends: [
    'eslint:recommended'
  ],
  plugins: [
    'svelte3'
  ],
  ignorePatterns: [
    'public/build/'
  ],
  overrides: [
    {
      files: ['**/*.svelte'],
      processor: 'svelte3/svelte3'
    }
  ],
  rules: {
    'no-var': 'error'
  },
  settings: {
    // Nothing
  }
}
.eslintignore
/node_modules/
/__sapper__/
/src/node_modules/@sapper/
/cypress/

Usage

  • package.json
package.json
"scripts": {
  "lint": "eslint . --ext .js,.svelte --fix",
},
$ npm run lint

Prettier

Install

$ npm i --save-dev prettier-plugin-svelte prettier

Settings

  • .prettierrc
.prettierrc
{
  "svelteSortOrder" : "styles-scripts-markup",
  "svelteStrictMode": true,
  "svelteBracketNewLine": true,
  "svelteAllowShorthand": false,

  "singleQuote": true,
  "trailingComma": "all",
  "printWidth": 120,
  "tabWidth": 2
}

Usage

  • package.json
package.json
"scripts": {
  "format": "prettier --write --svelte-sort-order scripts-markup-styles ./**/*.svelte",
},
$ npm run format

まとめ

Svelte や Sapper めっちゃ早くて快適だからもっと流行ってほしいものです。
あと、 Lint まわりは公式で入ってほしいななんて……。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした