Repository: prettier/prettier-atom (js)

Issue:
"Ignore Files in `.eslintignore`" does not work
<!--
Before you post an issue, please ensure that your issue is not with the
[prettier](https://github.com/prettier/prettier) or
[prettier-eslint](https://github.com/prettier/prettier-eslint) packages. This is just the
atom plugin that calls these packages under the hood.

Describe your issue here with as many details as possible
-->
By default this is enabled.
I added "test" in .eslintignore, so that linting ignores test files. Seems to work. Also disabled prettier formatting for my test files.
I disabled this feature in the prettier-atom config so I can prettify the test files.
I found that it did no prettifying on any of my test files on save.
I restarted atom and found the same.
Lastly, I removed "test" from .eslintignore and, on save of my test file, the prettifying started working again. So it definitely seems like this feature is having no effect.

I've done some research - I'm certain this is a feature specific to prettier-atom, not something in prettier or eslint themselves.

I'm afraid I can't figure out how to run Prettier: Debug (sorry!). But I can tell you I'm on 0.46.0 of the plugin.
<!--
Paste the output of the `Prettier: Debug` command below.
Protip: you can use a <details> tag to hide or show really large elements.

For example:
<details>
  A really long text
</details>
-->

  

Pull request:
Fix formatOnSave bug with eslintignore
- check "shouldRespectEslintignore" setting prior to checking whether
  the filepath should be eslintignore'd
- add tests for
  : should respect and is eslintignored
  : should not respect and is eslintignored
  : is not eslintignored

fixes #347

Patch:
diff --git a/.gitignore b/.gitignore
index 1695b2e..bb8a7f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ npm-debug.log
 coverage
 .opt-in
 .opt-out
+yarn-error.log
diff --git a/dist/formatOnSave/shouldFormatOnSave.js b/dist/formatOnSave/shouldFormatOnSave.js
index e727b39..c35b767 100644
--- a/dist/formatOnSave/shouldFormatOnSave.js
+++ b/dist/formatOnSave/shouldFormatOnSave.js
@@ -16,9 +16,10 @@ var _require3 = require('../atomInterface'),
     getExcludedGlobs = _require3.getExcludedGlobs,
     getWhitelistedGlobs = _require3.getWhitelistedGlobs,
     isDisabledIfNotInPackageJson = _require3.isDisabledIfNotInPackageJson,
-    isDisabledIfNoConfigFile = _require3.isDisabledIfNoConfigFile;
+    isDisabledIfNoConfigFile = _require3.isDisabledIfNoConfigFile,
+    shouldRespectEslintignore = _require3.shouldRespectEslintignore;
 
-var isFilePathEslintignored = require('./isFilePathEslintIgnored');
+var isFilePathEslintIgnored = require('./isFilePathEslintIgnored');
 var isFilePathPrettierIgnored = require('./isFilePathPrettierIgnored');
 var isPrettierInPackageJson = require('./isPrettierInPackageJson');
 
@@ -40,8 +41,7 @@ var noWhitelistGlobsPresent = _.flow(getWhitelistedGlobs, _.isEmpty);
 var isFilePathWhitelisted = _.flow(getCurrentFilePath, function (filePath) {
   return someGlobsMatchFilePath(getWhitelistedGlobs(), filePath);
 });
-
-var isFilePathNotEslintignored = _.flow(getCurrentFilePath, _.negate(isFilePathEslintignored));
+var isEslintIgnored = _.flow(getCurrentFilePath, isFilePathEslintIgnored);
 
 var isFilePathNotPrettierIgnored = _.flow(getCurrentFilePath, _.negate(isFilePathPrettierIgnored));
 
@@ -53,6 +53,6 @@ var isPrettierConfigPresent = function isPrettierConfigPresent(editor
   _.flow(getCurrentFilePath, getPrettierInstance(editor).resolveConfig.sync, _.negate(_.isNil))(editor);
 };
 
-var shouldFormatOnSave = _.overEvery([isFormatOnSaveEnabled, hasFilePath, isInScope, _.overSome([isFilePathWhitelisted, _.overEvery([noWhitelistGlobsPresent, filePathDoesNotMatchBlacklistGlobs])]), isFilePathNotEslintignored, isFilePathNotPrettierIgnored, _.overSome([_.negate(isDisabledIfNotInPackageJson), isPrettierInPackageJson]), _.overSome([_.negate(isDisabledIfNoConfigFile), isPrettierConfigPresent])]);
+var shouldFormatOnSave = _.overEvery([isFormatOnSaveEnabled, hasFilePath, isInScope, _.overSome([isFilePathWhitelisted, _.overEvery([noWhitelistGlobsPresent, filePathDoesNotMatchBlacklistGlobs])]), _.overSome([_.negate(shouldRespectEslintignore), _.negate(isEslintIgnored)]), isFilePathNotPrettierIgnored, _.overSome([_.negate(isDisabledIfNotInPackageJson), isPrettierInPackageJson]), _.overSome([_.negate(isDisabledIfNoConfigFile), isPrettierConfigPresent])]);
 
 module.exports = shouldFormatOnSave;
\ No newline at end of file
diff --git a/src/editorInterface/index.js b/src/editorInterface/index.js
index f045ddf..a491266 100644
--- a/src/editorInterface/index.js
+++ b/src/editorInterface/index.js
@@ -42,7 +42,7 @@ const isCurrentScopeMarkdownScope = (editor: TextEditor) =>
 
 const isCurrentScopeVueScope = (editor: TextEditor) => getVueScopes().includes(getCurrentScope(editor));
 
-const getCurrentFilePath = (editor: TextEditor) =>
+const getCurrentFilePath: (editor: TextEditor) => ?FilePath = editor =>
   editor.buffer.file ? editor.buffer.file.getPath() : undefined;
 
 const getCurrentDir: (editor: TextEditor) => ?string = editor =>
diff --git a/src/formatOnSave/isFilePathEslintIgnored.js b/src/formatOnSave/isFilePathEslintIgnored.js
index 7af65bb..31e8ada 100644
--- a/src/formatOnSave/isFilePathEslintIgnored.js
+++ b/src/formatOnSave/isFilePathEslintIgnored.js
@@ -26,7 +26,7 @@ const getIgnoredGlobsFromNearestEslintIgnore: (filePath: FilePath) => Globs = _.
   getLinesFromFilePath,
 );
 
-const isFilePathEslintignored: (filePath: FilePath) => boolean = _.flow(
+const isFilePathEslintignored: (filePath: ?FilePath) => boolean = _.flow(
   _.over([getIgnoredGlobsFromNearestEslintIgnore, getFilePathRelativeToEslintignore]),
   _.spread(someGlobsMatchFilePath),
 );
diff --git a/src/formatOnSave/shouldFormatOnSave.js b/src/formatOnSave/shouldFormatOnSave.js
index a39005c..78c2ab0 100644
--- a/src/formatOnSave/shouldFormatOnSave.js
+++ b/src/formatOnSave/shouldFormatOnSave.js
@@ -9,8 +9,9 @@ const {
   getWhitelistedGlobs,
   isDisabledIfNotInPackageJson,
   isDisabledIfNoConfigFile,
+  shouldRespectEslintignore,
 } = require('../atomInterface');
-const isFilePathEslintignored = require('./isFilePathEslintIgnored');
+const isFilePathEslintIgnored = require('./isFilePathEslintIgnored');
 const isFilePathPrettierIgnored = require('./isFilePathPrettierIgnored');
 const isPrettierInPackageJson = require('./isPrettierInPackageJson');
 
@@ -30,11 +31,7 @@ const isFilePathWhitelisted: (editor: TextEditor) => boolean = _.flow(
   getCurrentFilePath,
   (filePath: ?FilePath) => someGlobsMatchFilePath(getWhitelistedGlobs(), filePath),
 );
-
-const isFilePathNotEslintignored: (editor: TextEditor) => boolean = _.flow(
-  getCurrentFilePath,
-  _.negate(isFilePathEslintignored),
-);
+const isEslintIgnored: (editor: TextEditor) => boolean = _.flow(getCurrentFilePath, isFilePathEslintIgnored);
 
 const isFilePathNotPrettierIgnored: (editor: TextEditor) => boolean = _.flow(
   getCurrentFilePath,
@@ -55,7 +52,7 @@ const shouldFormatOnSave: (editor: TextEditor) => boolean = _.overEvery([
     isFilePathWhitelisted,
     _.overEvery([noWhitelistGlobsPresent, filePathDoesNotMatchBlacklistGlobs]),
   ]),
-  isFilePathNotEslintignored,
+  _.overSome([_.negate(shouldRespectEslintignore), _.negate(isEslintIgnored)]),
   isFilePathNotPrettierIgnored,
   _.overSome([_.negate(isDisabledIfNotInPackageJson), isPrettierInPackageJson]),
   _.overSome([_.negate(isDisabledIfNoConfigFile), isPrettierConfigPresent]),


Test patch:
diff --git a/src/formatOnSave/shouldFormatOnSave.test.js b/src/formatOnSave/shouldFormatOnSave.test.js
index 3f0e324..8304623 100644
--- a/src/formatOnSave/shouldFormatOnSave.test.js
+++ b/src/formatOnSave/shouldFormatOnSave.test.js
@@ -13,6 +13,7 @@ const {
   getExcludedGlobs,
   getWhitelistedGlobs,
   getAllScopes,
+  shouldRespectEslintignore,
 } = require('../atomInterface');
 const getPrettierInstance = require('../helpers/getPrettierInstance');
 const { getCurrentScope, getCurrentFilePath } = require('../editorInterface');
@@ -89,7 +90,8 @@ it('returns false if the filepath is not in scope', () => {
   expect(actual).toBe(false);
 });
 
-it('returns false if the filepath is eslintignored', () => {
+it('returns false if the filepath is eslintignored and eslintignore should be respected', () => {
+  shouldRespectEslintignore.mockImplementation(() => true);
   isFilePathEslintIgnored.mockImplementation(() => true);
 
   const actual = callShouldFormatOnSave();
@@ -97,6 +99,24 @@ it('returns false if the filepath is eslintignored', () => {
   expect(actual).toBe(false);
 });
 
+it('returns true if the filepath is eslintignored but eslintignore should _not_ be respected', () => {
+  shouldRespectEslintignore.mockImplementation(() => false);
+  isFilePathEslintIgnored.mockImplementation(() => true);
+
+  const actual = callShouldFormatOnSave();
+
+  expect(actual).toBe(true);
+});
+
+it('returns true if the filepath is not eslintignored', () => {
+  shouldRespectEslintignore.mockImplementation(() => true);
+  isFilePathEslintIgnored.mockImplementation(() => false);
+
+  const actual = callShouldFormatOnSave();
+
+  expect(actual).toBe(true);
+});
+
 it('returns false if the filepath is prettier ignored', () => {
   isFilePathPrettierIgnored.mockImplementation(() => true);