Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Doesn't work with global ESLint config #266

Open
corysimmons opened this issue Sep 13, 2017 · 8 comments
Open

Doesn't work with global ESLint config #266

corysimmons opened this issue Sep 13, 2017 · 8 comments

Comments

@corysimmons
Copy link

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.

@darahak
Copy link
Collaborator

darahak commented Sep 13, 2017

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?

@corysimmons
Copy link
Author

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?

@darahak
Copy link
Collaborator

darahak commented Sep 13, 2017

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.

@corysimmons
Copy link
Author

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.

@robwise
Copy link
Collaborator

robwise commented Dec 6, 2017

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

@zimme
Copy link
Member

zimme commented Dec 21, 2017

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).

@xeoncross
Copy link

xeoncross commented Apr 10, 2018

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

@jttmckee
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants