prettier-atom icon indicating copy to clipboard operation
prettier-atom copied to clipboard

Doesn't work with global ESLint config

Open corysimmons opened this issue 8 years ago • 8 comments

linter-eslint has a global option for falling back to ~/.eslintrc config if no configs are found locally.

image

Your README says prettier-atom looks up system tree for configs, but it doesn't seem to be working.

Here's my prettier-atom config:

image image

Atom version: 1.19.7
prettier-atom version: 0.38.0
prettier version: 1.6.1
prettier-eslint version: 6.4.3
prettier-atom configuration: {
  "formatOnSaveOptions": {
    "enabled": true,
    "showInStatusBar": true,
    "respectEslintignore": true,
    "javascriptScopes": [
      "source.js",
      "source.jsx",
      "source.js.jsx",
      "source.babel",
      "source.js-semantic",
      "text.html.basic",
      "text.html.vue"
    ],
    "typescriptScopes": [
      "source.ts",
      "source.tsx",
      "source.ts.tsx"
    ],
    "cssScopes": [
      "source.css",
      "source.less",
      "source.css.less",
      "source.scss",
      "source.css.scss"
    ],
    "jsonScopes": [
      "source.json"
    ],
    "graphQlScopes": [
      "source.graphql"
    ],
    "excludedGlobs": [],
    "whitelistedGlobs": [],
    "isDisabledIfNotInPackageJson": false
  },
  "prettierOptions": {
    "singleQuote": true,
    "bracketSpacing": true,
    "semi": true,
    "useTabs": false,
    "jsxBracketSameLine": false,
    "printWidth": 80,
    "tabWidth": "auto",
    "trailingComma": "none",
    "parser": "babylon"
  },
  "useEslint": true,
  "useEditorConfig": true,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}

It'd be nice if you could config to work with global .editorconfig as well.

corysimmons avatar Sep 13 '17 09:09 corysimmons

ESLint config resolution is supposed to be handled by prettier-eslint.

I think it's possible ESLint is picking up a config while crawling in the directory tree. Can you try to run eslint --print-config your-file.js and see what it gets?

darahak avatar Sep 13 '17 18:09 darahak

It seems like it is getting the correct config.

I think I figured it out:

image

Warns to disable linter-eslint "Fix on Save", but if you disable that, then it doesn't work with prettier-eslint.

So you need to enable both linter-eslint and prettier-atom.

Perhaps this recommendation can be removed?

corysimmons avatar Sep 13 '17 20:09 corysimmons

prettier-eslint should not depend on linter-eslint to make it work. The initial problem remains unsolved here.

prettier-eslint has a logger that you can enable to see what's happening. Open DevTools in Atom, and run in the console:

process.env.LOG_LEVEL='debug'
// or for more detailed traces
process.env.LOG_LEVEL='trace'

Then execute a format with ESLint integration enabled.

PS: I can't reproduce the issue. It can find my fallback config in my user dir.

darahak avatar Sep 13 '17 20:09 darahak

prettier-eslint [DEBUG]: There was a problem finding the eslint module. Using prettier-eslint's version. Cannot find module 'eslint' Error: Cannot find module 'eslint'

I'm trying to use a global prettier-eslint. It seems like it's not detecting that, whereas linter-eslint does have options for global eslint configs. That would explain why enabling both "Fix on Save"s worked, but isn't ideal.

Good solution: be able to specify global prettier-eslint and global eslint config, e.g. linter-eslint's settings page.

Not sure if it'd be better to step up tree or just allow people to specify a global prettier-eslint install and/or eslint config. Seems like specifying would leave less room for bugs and might be why the linter-eslint team went that route.

corysimmons avatar Sep 13 '17 21:09 corysimmons

The strange thing is that, it should be stepping up the tree as-is?

robwise avatar Dec 06 '17 04:12 robwise

prettier-eslint completely relies on eslints CLIEngines getConfigForFile function to get the config based on the file being linted or fall back to defaults if the text being linted isn't from a file (new unsaved file).

zimme avatar Dec 21 '17 17:12 zimme

If this helps at all, I'm having the same problem with prettier-eslint finding the file in the project path (one level higher than the package.json). Everything was has been working fine for months until I just noticed the change in formatting using ctrl+alt+f.

/Users/owner/.atom/packages/prettier-atom/node_modules/loglevel-colored-level-prefix/dist/index.js:54 prettier-eslint [DEBUG]: There was a problem finding the prettier module. Using prettier-eslint's version. Cannot find module 'prettier' Error: Cannot find module 'prettier'
    at Module._resolveFilename (module.js:470:15)
    at Module._resolveFilename (/Applications/Atom.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
at Function.get_Module._resolveFilename (/Applications/Atom.app/Contents/Resources/app/src/module-cache.js:354:58)
    at Function.requireRelative.resolve (/Users/owner/.atom/packages/prettier-atom/node_modules/require-relative/index.js:30:17)
    at getModulePath (/Users/owner/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/index.js:254:38)
...

prettier-atom 0.51.0

xeoncross avatar Apr 10 '18 17:04 xeoncross

This seems to be because prettier is looking for the eslint module which has been deprecated and can't now be installed, instead of the linter-eslint module.

I can't figure out how to get prettier to look for the correct module though

jttmckee avatar May 20 '19 15:05 jttmckee