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

Respect .prettierignore config #104

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ module.exports = {
!context.options[1] || context.options[1].usePrettierrc !== false;
const sourceCode = context.getSourceCode();
const source = sourceCode.text;
const sourceFileName = context.getFilename();

// The pragma is only valid if it is found in a block comment at the very
// start of the file.
Expand Down Expand Up @@ -401,19 +402,26 @@ module.exports = {
usePrettierrc &&
prettier.resolveConfig &&
prettier.resolveConfig.sync
? prettier.resolveConfig.sync(context.getFilename(), {
? prettier.resolveConfig.sync(sourceFileName, {
editorconfig: true
})
: null;
const prettierOptions = Object.assign(
{},
prettierRcOptions,
eslintPrettierOptions,
{ filepath: context.getFilename() }
{ filepath: sourceFileName }
);

const prettierSource = prettier.format(source, prettierOptions);
if (source !== prettierSource) {
const sourceFileInfo =
prettier.getFileInfo &&
prettier.getFileInfo.sync &&
prettier.getFileInfo.sync(sourceFileName, {
ignorePath: '.prettierignore'
});
const sourceFileIgnored = sourceFileInfo && sourceFileInfo.ignored;

if (!sourceFileIgnored && source !== prettierSource) {
const differences = generateDifferences(source, prettierSource);

differences.forEach(difference => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"eslint-plugin-self": "^1.0.1",
"mocha": "^3.1.2",
"moment": "^2.18.1",
"prettier": "^1.10.2",
"prettier": "^1.13.0",
"semver": "^5.3.0",
"vue-eslint-parser": "^2.0.2"
},
Expand Down