2
votes

I'm trying to achieve this:

Using VS Code as my Editor for JavaScript and TypeScript, having formatting rules from eslint-config-google applied automatically when saving a JavaScript/TypeScript document.

My devDependencies are these:

  "devDependencies": {
    "@types/node": "^10.12.18",
    "@typescript-eslint/eslint-plugin": "^1.9.0",
    "@typescript-eslint/parser": "^1.9.0",
    "eslint": "5.16.0",
    "eslint-config-google": "0.13.0",
    "eslint-config-prettier": "^6.0.0",
    "eslint-plugin-prettier": "^3.1.0",
    "prettier": "^1.18.2",
    "typescript": "^3.4.3"
  }

My .eslintrc:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "prettier"],
  "extends": ["eslint:recommended", "google", "prettier"],
  "parserOptions": {
    "ecmaVersion": 2016,
    "sourceType": "module"
  },
  "env": {
    "es6": true,
    "node": true,
    "mocha": true
  },
  "rules": {
    "prettier/prettier": ["error"]
  }
}

My .prettierc:

{
  "printWidth": 100,
  "singleQuote": true
}

I have installed prettier and eslint extensions in VS Code and enabled format on Save.

Considering this code:

'use strict';

describe('some test', () => {
  it('should return a string value', (done) => {
    return done();
  });
});

Neither ESLint nor Prettier are complaining, but when saving the document, Prettier removes the parentheses around done also eslint-config-google defines them as required.

Also, when removing the parentheses around done, no error is shown, also they're required.

Looks like eslint-config-google and Prettier are not in sync which is likely my fault.

Whats wrong here?

1
This is more of a side note, you could consider using prettier-eslint to ensure prettier is using your eslint rules to format.Alexander Staroselsky
@AlexanderStaroselsky this indeed works fine on the command line.Alexander Zeitler

1 Answers

1
votes

I'm strugling with similar stuff, but using webStorm from jetbrains, and some different tech stack, but maybe following configuration might work for you, please take a look at my settiong:

devDependencies

"eslint": "7.12.0",
"eslint-config-google": "0.14.0",
"eslint-config-react-app": "6.0.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "7.21.5",
"eslint-plugin-react-hooks": "4.2.0",

.prettierrc

{
  "extends": [
    "plugin:prettier/recommended"
  ],
  "bracketSpacing": false,
  "tabWidth": 2,
  "useTabs": false,
  "trailingComma": "all",
  "singleQuote": true
}

.eslintrc.js

module.exports = {
  env: {
    browser: true,
    es6: true,
  },
  extends: ['plugin:react/recommended', 'google'],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
  },
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 2018,
    sourceType: 'module',
  },
  plugins: ['react', 'prettier'],
  rules: {
    'prettier/prettier': 'error',
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
};