Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
fix(ignores): ensure we always pass a relative string to the ignores …
Browse files Browse the repository at this point in the history
…package
  • Loading branch information
robwise committed Nov 19, 2018
1 parent 1507075 commit c6ad510
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions decls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ declare var atom: {
packages: {
isPackageActive: (name: string) => boolean,
},
project: {
relativizePath: (path: string) => [string | null, string],
},
tooltips: {
add: (target: HTMLElement, options?: Atom$Tooltips$Options) => Atom$Disposable,
},
Expand Down
5 changes: 5 additions & 0 deletions dist/atomInterface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const _ = require('lodash/fp');

// constants
const LINTER_LINT_COMMAND = 'linter:lint';

Expand Down Expand Up @@ -68,6 +70,8 @@ const attemptWithErrorNotification = (() => {

const runLinter = editor => isLinterLintCommandDefined(editor) && atom.commands.dispatch(atom.views.getView(editor), LINTER_LINT_COMMAND);

const relativizePathFromAtomProject = path => path ? _.get('[1]', atom.project.relativizePath(path)) : null;

module.exports = {
addErrorNotification,
addInfoNotification,
Expand All @@ -82,6 +86,7 @@ module.exports = {
isDisabledIfNoConfigFile,
isFormatOnSaveEnabled,
isLinterEslintAutofixEnabled,
relativizePathFromAtomProject,
runLinter,
shouldRespectEslintignore,
shouldUseEslint,
Expand Down
2 changes: 1 addition & 1 deletion dist/formatOnSave/isFilePathEslintIgnored.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getNearestEslintignorePath = filePath => findCachedFromFilePath(filePath,

const safeRelativePath = _.curry(
// $FlowFixMe
(from, to) => !!from && !!to ? path.relative(from, to) : undefined);
(from, to) => !!from && !!to ? path.join(path.relative(from, to)) : undefined);

const getFilePathRelativeToEslintignore = (filePath
// $FlowIssue: lodashfp placeholders not supported yet
Expand Down
5 changes: 3 additions & 2 deletions dist/formatOnSave/shouldFormatOnSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ const {
isFormatOnSaveEnabled,
isDisabledIfNotInPackageJson,
isDisabledIfNoConfigFile,
relativizePathFromAtomProject,
shouldRespectEslintignore
} = require('../atomInterface');
const isFilePathEslintIgnored = require('./isFilePathEslintIgnored');
const isPrettierInPackageJson = require('./isPrettierInPackageJson');

const hasFilePath = editor => !!getCurrentFilePath(editor);

const filePathDoesNotMatchBlacklistGlobs = _.flow(getCurrentFilePath, filePath => _.negate(someGlobsMatchFilePath)(getExcludedGlobs(), filePath));
const filePathDoesNotMatchBlacklistGlobs = _.flow(getCurrentFilePath, relativizePathFromAtomProject, filePath => _.negate(someGlobsMatchFilePath)(getExcludedGlobs(), filePath));

// $FlowFixMe
const noWhitelistGlobsPresent = _.flow(getWhitelistedGlobs, _.isEmpty);

const isFilePathWhitelisted = _.flow(getCurrentFilePath, filePath => someGlobsMatchFilePath(getWhitelistedGlobs(), filePath));
const isFilePathWhitelisted = _.flow(getCurrentFilePath, relativizePathFromAtomProject, filePath => someGlobsMatchFilePath(getWhitelistedGlobs(), filePath));

const isEslintIgnored = _.flow(getCurrentFilePath, isFilePathEslintIgnored);

Expand Down
5 changes: 5 additions & 0 deletions src/atomInterface/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
const _ = require('lodash/fp');

// constants
const LINTER_LINT_COMMAND = 'linter:lint';
Expand Down Expand Up @@ -67,6 +68,9 @@ const runLinter = (editor: TextEditor) =>
isLinterLintCommandDefined(editor) &&
atom.commands.dispatch(atom.views.getView(editor), LINTER_LINT_COMMAND);

const relativizePathFromAtomProject = (path: ?string) =>
path ? _.get('[1]', atom.project.relativizePath(path)) : null;

module.exports = {
addErrorNotification,
addInfoNotification,
Expand All @@ -81,6 +85,7 @@ module.exports = {
isDisabledIfNoConfigFile,
isFormatOnSaveEnabled,
isLinterEslintAutofixEnabled,
relativizePathFromAtomProject,
runLinter,
shouldRespectEslintignore,
shouldUseEslint,
Expand Down
3 changes: 2 additions & 1 deletion src/formatOnSave/isFilePathEslintIgnored.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const getNearestEslintignorePath = (filePath: FilePath): ?FilePath =>

const safeRelativePath = _.curry(
// $FlowFixMe
(from: ?FilePath, to: ?FilePath): ?FilePath => (!!from && !!to ? path.relative(from, to) : undefined),
(from: ?FilePath, to: ?FilePath): ?FilePath =>
!!from && !!to ? path.join(path.relative(from, to)) : undefined,
);

const getFilePathRelativeToEslintignore = (filePath: FilePath): ?FilePath =>
Expand Down
3 changes: 3 additions & 0 deletions src/formatOnSave/shouldFormatOnSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
isFormatOnSaveEnabled,
isDisabledIfNotInPackageJson,
isDisabledIfNoConfigFile,
relativizePathFromAtomProject,
shouldRespectEslintignore,
} = require('../atomInterface');
const isFilePathEslintIgnored = require('./isFilePathEslintIgnored');
Expand All @@ -22,6 +23,7 @@ const hasFilePath = (editor: TextEditor) => !!getCurrentFilePath(editor);

const filePathDoesNotMatchBlacklistGlobs: (editor: TextEditor) => boolean = _.flow(
getCurrentFilePath,
relativizePathFromAtomProject,
(filePath: ?FilePath) => _.negate(someGlobsMatchFilePath)(getExcludedGlobs(), filePath),
);

Expand All @@ -33,6 +35,7 @@ const noWhitelistGlobsPresent: () => boolean = _.flow(

const isFilePathWhitelisted: (editor: TextEditor) => boolean = _.flow(
getCurrentFilePath,
relativizePathFromAtomProject,
(filePath: ?FilePath) => someGlobsMatchFilePath(getWhitelistedGlobs(), filePath),
);

Expand Down
2 changes: 2 additions & 0 deletions src/formatOnSave/shouldFormatOnSave.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
isFormatOnSaveEnabled,
getExcludedGlobs,
getWhitelistedGlobs,
relativizePathFromAtomProject,
shouldRespectEslintignore,
} = require('../atomInterface');
const getPrettierInstance = require('../helpers/getPrettierInstance');
Expand All @@ -31,6 +32,7 @@ beforeEach(() => {
isFormatOnSaveEnabled.mockImplementation(() => true);
isFileFormattable.mockImplementation(() => true);
getCurrentFilePath.mockImplementation(() => fakeCurrentFilePath);
relativizePathFromAtomProject.mockImplementation(() => fakeCurrentFilePath);
isFilePathEslintIgnored.mockImplementation(() => false);
isPrettierProperVersion.mockImplementation(() => true);
isDisabledIfNotInPackageJson.mockImplementation(() => false);
Expand Down

0 comments on commit c6ad510

Please sign in to comment.