Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "target_files" option to config file #3764

Closed
nwshane opened this issue Jan 18, 2018 · 7 comments
Closed

Add "target_files" option to config file #3764

nwshane opened this issue Jan 18, 2018 · 7 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@nwshane
Copy link

nwshane commented Jan 18, 2018

Current behavior:

No option (as far as I can tell) to specify the glob I want to target in the .prettierrc config file.

Expected behavior:

It would be great to have a "target_files" option in the .prettierrc config file, which would allow you to specify which files you want prettier to target. That way, I could configure my editor's prettier linter only to change files that match the glob. Right now, there seems to be a .prettierignore file which my editor's linter can use, but .prettierignore only allows blacklisting files instead of whitelisting files.

I hope this request makes sense! I love prettier - thanks for all your awesome work.

@ikatyang ikatyang added type:enhancement A potential new feature to be added, or an improvement to how we print something status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels Jan 19, 2018
@ikatyang
Copy link
Member

Similar to #3460 but in config file.

If we're going to add this feature, I'd expect --config should be provided explicitly since it's a project-level config and the default behavior is to find config files up to the tree for each file, which is impossible to get the correct glob.

@azz
Copy link
Member

azz commented Jan 19, 2018

(Kind of) duplicate of #2691. I think it could be confusing having file lists in the config file. Instead we should default the CLI to run on **/{js,ts,css,...} (#3503).

@ikatyang
Copy link
Member

How about adding an enable: boolean option so that we could select/ignore files using overrides? though there's already a requirePragma.

@hawkrives
Copy link
Contributor

hawkrives commented Jan 19, 2018

Oh that's a good idea. Ignore certain patterns by setting requirePragma. I'll have to steal that.

@ikatyang
Copy link
Member

After second thought, I think using requirePragma should be enough since nobody will use requirePragma and want to ignore files contains pragma, and it should be supported by every editor integration. (And it does not need to set --config explicitly if we want to add this feature.)

prettier "**/*.{js,ts,css}" --write 
{
  "requirePragma": true,
  "overrides": [
    {
      "files": ["glob-you-want-to-format"],
      "excludeFiles": ["glob-you-want-to-ignore"],
      "options": { "requirePragma": false }
    }
  ]
}

Feel free to reopen if it does not address the issue.

@nwshane
Copy link
Author

nwshane commented Jan 22, 2018

@ikatyang Thanks a lot! This solves most of my issue, although there's still one improvement I'd love to be able to make. At the moment, I have my file glob (frontend/src/**/*.{css,js,json,less}) defined twice: once in an npm script that uses the prettier command, and again in the prettier config file. Ideally I'd like to be able to define it only once, presumably in the configuration file, and let the prettier CLI command just use the config file's settings by default. That way, I won't have to remember to always change the glob in two places in the future.

The prettier command currently errors out if it's not provided with a glob. Would you consider changing prettier so that it doesn't require a glob, in order to make the config file the "source of all truth"?

@azz
Copy link
Member

azz commented Jan 22, 2018

@nwshane We have, and will probably do this in Prettier 2.0 (#3503)

#2691 - CLI defaults to "**/*.{js,ts,...}".
People should just be able to do prettier --write without passing messy globs #0CJS

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 6, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests

4 participants