Code Monkey home page Code Monkey logo

Comments (6)

ikatyang avatar ikatyang commented on June 8, 2024

Thanks for the report, but I have no idea how to fix it properly since cosmiconfig (prettier use this module to find config) will lookup its file system structure to find the config file, that is, the config file can be anywhere in its parent directory, not only look at the root folder. As far as I know, caches won't remain its fs structure, they're always flattened.

In my opinion, this issue should be fixed on the editor/editor-plugin side since they touched the file path, so they should have the responsibility to correct them back, but I'm open to fix this on my side if the proposal is reasonable.

from tslint-plugin-prettier.

n0nick avatar n0nick commented on June 8, 2024

Thanks for the quick response @ikatyang.

I'm not too familiar with cosmiconfig or the prettier logic, but I imagined something like the following replacing prettierRule.ts:37-42:

const resolved_config =
  prettier.resolveConfig.sync(source_file.fileName) ||
  prettier.resolveConfig.sync(process.cwd());
if (resolved_config !== null) {
  options = resolved_config;
}

If this sounds like wanted behavior for tslint-plugin-prettier, I can try and see if that would work.

from tslint-plugin-prettier.

n0nick avatar n0nick commented on June 8, 2024

It even seems that cosmiconfig defaults to process.cwd() when no search path is specified:
https://github.com/davidtheclark/cosmiconfig#usage

from tslint-plugin-prettier.

ikatyang avatar ikatyang commented on June 8, 2024

Prettier CLI always find config based on its filepath:

https://github.com/prettier/prettier/blob/1.7.0/src/cli-util.js#L245
https://github.com/prettier/prettier/blob/1.7.0/src/cli-util.js#L257

I'd like to keep the same behavior with CLI so that people can move smoothly if they want to switch back to use CLI. Another solution is to specify a config file path manually, e.g.

{
  "rules": {
    "prettier": [true, "path/to/config/file/search/path/based/on/cwd"]
  }
}

And you'll have to set something like "prettier": [true, "."] to indicate looking in the current work directory.

Is that looks good to you?

from tslint-plugin-prettier.

n0nick avatar n0nick commented on June 8, 2024

I agree re consistency with the CLI, I see your point.

If something like what you suggest is easy to add and would work with a relative path (i.e. "."), that would be awesome.
Especially since I don't have a better idea for the editor plugin's side (they want to allow linting before saves, so files need to be outside of project scope).

from tslint-plugin-prettier.

n0nick avatar n0nick commented on June 8, 2024

Thank you @ikatyang for the responsiveness and quick turnaround! 🎉

from tslint-plugin-prettier.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.