-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Support prettierignore and custom processors #111
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package.json | ||
|
||
# this file doesn't exist, but we use it as a filename that should be ignored | ||
# by prettier in the tests | ||
ignore-me.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,24 @@ ruleTester.run('prettier', rule, { | |
code: `var foo = {bar: 0};\n`, | ||
filename: getPrettierRcJsFilename('bracket-spacing'), | ||
options: [{ bracketSpacing: false }, { usePrettierrc: false }] | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for the parser blacklist behavior? We don't need to actually include processors, but maybe one way to do it would be to put JavaScript code in a file with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. I tried doing this with including a plugin, but I couldn't get the plugin to be applied within a RuleTester. Forcing the extension is a good middle ground |
||
// Ignores filenames in .prettierignore | ||
{ | ||
code: `("");\n`, | ||
filename: getPrettierRcJsFilename('single-quote', 'ignore-me.js') | ||
}, | ||
// Sets a default parser when it can't be inferred from the file extensions | ||
{ | ||
code: `('');\n`, | ||
filename: getPrettierRcJsFilename('single-quote', 'dummy.qqq') | ||
}, | ||
// Overwrites the parser for file extensions prettier would try to format | ||
// with not the babylon parser | ||
// In the real world, eslint-plugin-markdown would transform file contents | ||
// into JS snippets that would get passed to ESLint | ||
{ | ||
code: `('');\n`, | ||
filename: getPrettierRcJsFilename('single-quote', 'dummy.md') | ||
} | ||
], | ||
invalid: [ | ||
|
@@ -175,9 +193,12 @@ function loadInvalidFixture(name) { | |
|
||
/** | ||
* Builds a dummy javascript file path to trick prettier into resolving a specific .prettierrc file. | ||
* @param {string} name - Prettierrc fixture basename. | ||
* @param {string} dir - Prettierrc fixture basename. | ||
* @returns {string} A javascript filename relative to the .prettierrc config. | ||
*/ | ||
function getPrettierRcJsFilename(name) { | ||
return path.resolve(__dirname, `./prettierrc/${name}/dummy.js`); | ||
function getPrettierRcJsFilename(dir, file) { | ||
// Use default parameters when we drop support for node 4 | ||
file = typeof file !== 'undefined' ? file : 'dummy.js'; | ||
|
||
return path.resolve(__dirname, `./prettierrc/${dir}/${file}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list seems like it might plausibly need to expand in the future. The detailed comment above it with background is definitely appreciated, but since the situation is fairly complex and difficult to comprehend, is there a simple description we can add for what the list should contain for future reference?
For example, maybe we could add a comment stating that: