質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
ESLint

ESLintは、JavaScriptのための構文チェックツール。全検証ルールを自由に on/offでき、独自のプロジェクトに合わせたカスタムルールを容易に設定することが可能。公開されている様々なプラグインを組み込んで使用することもできます。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

0回答

3058閲覧

ESLintで--fixを実行しても修正されずにエラーメッセージが表示される(Prettierとの兼ね合いも)

moimoi_sushi

総合スコア26

ESLint

ESLintは、JavaScriptのための構文チェックツール。全検証ルールを自由に on/offでき、独自のプロジェクトに合わせたカスタムルールを容易に設定することが可能。公開されている様々なプラグインを組み込んで使用することもできます。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2020/06/21 04:22

編集2020/06/21 04:23

前提・実現したいこと

ESLintで eslint --fix ソース名 を実行させてソースコードを整形したいです。

発生している問題・エラーメッセージ

ESLintで表示されるほとんどのエラーはPrettier関連なのですが、Prettierは既にVSCodeとpackageにも導入しており自動で整形された後のコードになっていますが怒られてしまいます。

教材の内容をコピペしてESLintの設定をしており設定を把握できていないところもあるかと思います。

該当のソースコード

✖ 15 problems (15 errors, 0 warnings) 13 errors and 0 warnings potentially fixable with the `--fix` option.

eslint --fix を実行しても同じメッセージが表示されfixできません。
以下はエラーメッセージ全文です。

/Users/myuser/hoge.ts 1:23 error Strings must use singlequote quotes 2:19 error Strings must use singlequote quotes 3:16 error Strings must use singlequote quotes 4:19 error 'csv-parse' should be listed in the project's dependencies, not devDependencies import/no-extraneous-dependencies 4:19 error Strings must use singlequote quotes 6:27 error Strings must use singlequote quotes 7:32 error Strings must use singlequote quotes 8:28 error Strings must use singlequote quotes 10:28 error Strings must use singlequote quotes 23:16 error Strings must use singlequote quotes 24:29 error Definition for rule '@typescript-eslint/camelcase' was not found @typescript-eslint/camelcase 48:23 error Strings must use singlequote quotes 54:12 error Strings must use singlequote quotes 54:21 error Strings must use singlequote quotes 55:14 error Strings must use singlequote quotes /Users/myuser/hoge2.ts 1:19 error Replace `'firebase-admin'` with `"firebase-admin"` prettier/prettier 2:32 error Replace `'../services/mangarel/constants'` with `"../services/mangarel/constants"` prettier/prettier 4:27 warning Missing return type on function @typescript-eslint/explicit-module-boundary-types /Users/myuser/hoge3.ts 1:28 error Replace `'firebase-functions'` with `"firebase-functions"` prettier/prettier 2:19 error Replace `'firebase-admin'` with `"firebase-admin"` prettier/prettier 3:32 error Replace `'./services/mangarel/constants'` with `"./services/mangarel/constants"` prettier/prettier 8:11 error Replace `'asia-northeast1'` with `"asia-northeast1"` prettier/prettier /Users/myuser/hoge4.ts 2:12 error Replace `'authors'` with `"authors"` prettier/prettier 3:10 error Replace `'books'` with `"books"` prettier/prettier 4:10 error Replace `'users'` with `"users"` prettier/prettier 5:15 error Replace `'publishers'` with `"publishers"` prettier/prettier 6:16 error Replace `'docCounters'` with `"docCounters"` prettier/prettier 7:14 error Replace `'feedMemos'` with `"feedMemos"` prettier/prettier /Users/myuser/hoge5.ts 1:27 error Replace `'firebase/app'` with `"firebase/app"` prettier/prettier 13:9 error Replace `''` with `""` prettier/prettier ✖ 30 problems (29 errors, 1 warning) 27 errors and 0 warnings potentially fixable with the `--fix` option.

シングルクォートを使ってくださいというところをPrettierでシングルクォート設定にしたとしても一緒くたに全てのコードがシングルクォートへ変えられてしまうため今度はダブルクォートにしてくださいと怒られます。ESLintで修正するしかないと考えています。

package.jsonは以下です。

PackageJSONの中身

1{ 2 "name": "functions", 3 "scripts": { 4 "build": "npm run lint && tsc", 5 "dbreset": "firebase firestore:delete --all-collections", 6 "dbreset:publishers": "firebase firestore:delete -y --shallow publishers", 7 "dbseed": "npm run dbseed:publishers", 8 "dbseed:publishers": "node lib/commands/dbseed.js publishers seeds/publishers.tsv", 9 "lint": "eslint 'src/**/*.{js,ts}'", 10 "lint:fix": "eslint --fix 'src/**/*.{js,ts}'", 11 "logs": "firebase functions:log", 12 "serve": "npm run build && firebase serve --only functions", 13 "shell": "npm run build && firebase functions:shell", 14 "start": "npm run shell", 15 "test": "jest" 16 }, 17 "engines": { 18 "node": "10" 19 }, 20 "main": "lib/index.js", 21 "dependencies": { 22 "commander": "^5.1.0", 23 "firebase": "^7.15.3", 24 "firebase-admin": "^8.10.0", 25 "firebase-functions": "^3.6.1" 26 }, 27 "devDependencies": { 28 "@types/eslint": "^7.2.0", 29 "@types/eslint-plugin-prettier": "^3.1.0", 30 "@types/jest": "^26.0.0", 31 "@types/node": "^14.0.13", 32 "@types/prettier": "^2.0.1", 33 "@types/react-app": "^1.0.5", 34 "@typescript-eslint/eslint-plugin": "^3.3.0", 35 "@typescript-eslint/parser": "^3.3.0", 36 "csv-parse": "^4.10.1", 37 "eslint": "6.7.2", 38 "eslint-config-airbnb-base": "^14.2.0", 39 "eslint-config-prettier": "^6.11.0", 40 "eslint-plugin-import": "^2.21.2", 41 "eslint-plugin-jest": "^23.13.2", 42 "eslint-plugin-prefer-arrow": "^1.2.1", 43 "eslint-plugin-prettier": "^3.1.4", 44 "firebase-functions-test": "^0.2.0", 45 "jest": "^26.0.1", 46 "prettier": "^2.0.5", 47 "react-app": "^1.1.2", 48 "ts-jest": "^26.1.0", 49 "typescript": "^3.8.0" 50 }, 51 "private": true, 52 "jest": { 53 "preset": "ts-jest", 54 "testRegex": "(/__tests__/.*|\.(test|spec))\.(ts?|js?)$", 55 "moduleFileExtensions": [ 56 "ts", 57 "json", 58 "js" 59 ] 60 } 61} 62

.eslintrc.jsは以下です。

ESLintの設定

1module.exports = { 2 env: { 3 browser: true, 4 es6: true, 5 node: true, 6 "jest/globals": true, 7 }, 8 extends: [ 9 "airbnb-base", 10 "eslint:recommended", 11 "plugin:@typescript-eslint/eslint-recommended", 12 "plugin:@typescript-eslint/recommended", 13 "plugin:import/errors", 14 "plugin:import/warnings", 15 "plugin:import/typescript", 16 "plugin:jest/recommended", 17 "plugin:prettier/recommended", 18 "prettier", 19 "prettier/@typescript-eslint", 20 "prettier/standard", 21 ], 22 globals: { 23 Atomics: "readonly", 24 cy: "readonly", 25 Cypress: "readonly", 26 SharedArrayBuffer: "readonly", 27 __DEV__: true, 28 }, 29 parser: "@typescript-eslint/parser", 30 parserOptions: { 31 ecmaVersion: 2018, 32 project: "./tsconfig.json", 33 sourceType: "module", 34 }, 35 plugins: ["@typescript-eslint", "import", "jest", "prefer-arrow", "prettier"], 36 root: true, 37 rules: { 38 // eslint official 39 "linebreak-style": ["error", "unix"], 40 "newline-before-return": "error", 41 "no-console": "warn", 42 "no-continue": "off", 43 quotes: ["error", "single", { avoidEscape: true }], 44 "require-yield": "error", 45 semi: ["error", "always"], 46 47 // @typescript-eslint 48 "@typescript-eslint/explicit-function-return-type": "off", 49 "@typescript-eslint/explicit-member-accessibility": "off", 50 indent: "off", 51 "@typescript-eslint/indent": "off", 52 "@typescript-eslint/no-unnecessary-type-assertion": "error", 53 "@typescript-eslint/no-unused-vars": "error", 54 "@typescript-eslint/prefer-interface": "off", 55 56 // airbnb 57 "no-restricted-syntax": [ 58 "error", 59 { 60 selector: "ForInStatement", 61 message: 62 "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.", 63 }, 64 { 65 selector: "LabeledStatement", 66 message: 67 "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.", 68 }, 69 { 70 selector: "WithStatement", 71 message: 72 "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.", 73 }, 74 ], 75 // prefer-arrow 76 "prefer-arrow/prefer-arrow-functions": [ 77 "error", 78 { 79 disallowPrototype: true, 80 singleReturnOnly: true, 81 classPropertiesAllowed: false, 82 }, 83 ], 84 85 // import 86 "import/extensions": [ 87 "error", 88 "always", 89 { 90 js: "never", 91 ts: "never", 92 }, 93 ], 94 "import/no-extraneous-dependencies": [ 95 "error", 96 { 97 devDependencies: [ 98 ".storybook/**", 99 "stories/**", 100 "**/*/*.story.*", 101 "**/*/*.stories.*", 102 "**/__specs__/**", 103 "**/*/*.spec.*", 104 "**/__tests__/**", 105 "**/*/*.test.*", 106 "src/setupTests.*", 107 ], 108 }, 109 ], 110 "import/prefer-default-export": "off", 111 }, 112 settings: { 113 "import/parsers": { 114 "@typescript-eslint/parser": [".ts", ".tsx"], 115 }, 116 "import/resolver": { 117 node: { 118 extensions: [".js", ".ts"], 119 paths: ["src"], 120 }, 121 }, 122 }, 123}; 124

よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問