Comments (6)
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.
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.
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.
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.
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.
Thank you @ikatyang for the responsiveness and quick turnaround! 🎉
from tslint-plugin-prettier.
Related Issues (15)
- Difference to existing project? HOT 7
- Not report the error when prettier fails. HOT 2
- Not support .editorconfig file
- Use prettier-linter-helpers HOT 1
- Prettier Parsing Error While Typing
- Update Dependencies (Renovate Bot)
- Try to resolve config path relative to tslint.json if config file not found. HOT 2
- Respect prettierignore HOT 1
- Is it possible to run prettier on save? HOT 3
- when using space-before-function-paren , getting conflicted rules HOT 3
- "tslint.configFile" absolute file path required with VSCode HOT 3
- support prettier v2
- readme.md seems wrong about configuration HOT 4
- Auto fix needs to be run several times to fix formatting HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tslint-plugin-prettier.