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

Bump dependencies #734

Merged
merged 5 commits into from
Apr 14, 2020
Merged
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
3 changes: 2 additions & 1 deletion decls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare type TextEditor = {
},
},
backwardsScanInBufferRange: (regex: RegExp, Range: Range, iterator: Atom$Iterator) => void,
...
};
declare type TextBuffer = {
characterIndexForPosition: (cursorPosition: Point) => number,
Expand Down Expand Up @@ -91,7 +92,7 @@ declare var atom: {
add: (target: HTMLElement, options?: Atom$Tooltips$Options) => Atom$Disposable,
},
views: {
getView: Atom$Workspace => Atom$View,
getView: (Atom$Workspace) => Atom$View,
},
workspace: Atom$Workspace,
getVersion: () => string,
Expand Down
4 changes: 1 addition & 3 deletions dist/atomInterface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ const addWarningNotification = (message, options) => atom.notifications.addWarni

const addErrorNotification = (message, options) => atom.notifications.addError(message, options);

const attemptWithErrorNotification =
/*#__PURE__*/
function () {
const attemptWithErrorNotification = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])(function* (func, ...args) {
try {
yield func(...args);
Expand Down
10 changes: 3 additions & 7 deletions dist/executePrettier/executePrettierOnBufferRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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

Expand Down Expand Up @@ -70,9 +70,7 @@ const buildPrettierStylelintOptions = (editor, text) => ({

const executePrettierStylelint = (editor, text) => prettierStylelint.format(buildPrettierStylelintOptions(editor, text));

const executePrettierOrIntegration =
/*#__PURE__*/
function () {
const executePrettierOrIntegration = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])(function* (editor, text, cursorOffset) {
if (shouldUseStylelint() && isCurrentScopeStyleLintScope(editor)) {
// TODO: add support for cursor position - https://github.com/hugomrdias/prettier-stylelint/issues/13
Expand Down Expand Up @@ -111,9 +109,7 @@ function () {
};
}();

const executePrettierOnBufferRange =
/*#__PURE__*/
function () {
const executePrettierOnBufferRange = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])(function* (editor, bufferRange, options) {
// grab cursor position and file contents
const currentBuffer = editor.getBuffer();
Expand Down
54 changes: 14 additions & 40 deletions dist/executePrettier/executePrettierOnBufferRange.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

jest.mock('@lewisl9029/prettier-eslint');
jest.mock('prettier-stylelint');
Expand Down Expand Up @@ -76,38 +76,30 @@ beforeEach(() => {
getPrettierInstance.mockImplementation(() => prettier);
prettier.resolveConfig.sync.mockImplementation(() => optionsFixture);
});
it('uses editor config',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('uses editor config', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
getCurrentFilePath.mockImplementation(() => 'foo.js');
shouldUseEditorConfig.mockImplementation(() => true);
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(prettier.resolveConfig.sync).toHaveBeenCalledWith('foo.js', {
editorconfig: true
});
}));
it('does not use editor config',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('does not use editor config', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
getCurrentFilePath.mockImplementation(() => 'foo.js');
shouldUseEditorConfig.mockImplementation(() => false);
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(prettier.resolveConfig.sync).toHaveBeenCalledWith('foo.js', {
editorconfig: false
});
}));
it('sets the transformed text in the buffer range',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('sets the transformed text in the buffer range', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(editor.setTextInBufferRange).toHaveBeenCalled(); // NOTE: there is currently a bug in prettier that causes formatWithCursor to
// only return the formatted text when running in test environment, but works
// as expected when in production.
// expect(editor.setTextInBufferRange).toHaveBeenCalledWith(bufferRangeFixture, formattedFixture);
}));
it('uses Prettier#formatWithCursor',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('uses Prettier#formatWithCursor', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const cursorOffset = 10;
editor.getBuffer.mockImplementation(() => ({
getRange: () => ({
Expand All @@ -124,9 +116,7 @@ it('uses Prettier#formatWithCursor',
cursorOffset
}, optionsFixture));
}));
it('sets the transformed text via diff when the option is passed',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('sets the transformed text via diff when the option is passed', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const setTextViaDiffMock = jest.fn();
editor.getBuffer.mockImplementation(() => ({
getRange: () => ({
Expand All @@ -150,15 +140,11 @@ it('sets the transformed text via diff when the option is passed',
// as expected when in production.
// expect(setTextViaDiffMock).toHaveBeenCalledWith(formattedFixture);
}));
it('runs linter:lint if available to refresh linter highlighting',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('runs linter:lint if available to refresh linter highlighting', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(runLinter).toHaveBeenCalledWith(editor);
}));
it('transforms the given buffer range using prettier-eslint if config enables it',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('transforms the given buffer range using prettier-eslint if config enables it', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
shouldUseEslint.mockImplementation(() => true);
const prettierLast = true;
getPrettierEslintOptions.mockImplementation(() => ({
Expand All @@ -172,9 +158,7 @@ it('transforms the given buffer range using prettier-eslint if config enables it
text: sourceFixture
});
}));
it('transforms the given buffer range using prettier-stylelint if scope is CSS and config enables it',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('transforms the given buffer range using prettier-stylelint if scope is CSS and config enables it', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
isCurrentScopeStyleLintScope.mockImplementation(() => true);
shouldUseStylelint.mockImplementation(() => true);
const filePath = 'foo.js';
Expand All @@ -189,9 +173,7 @@ describe('when text in buffer range is already pretty', () => {
beforeEach(() => {
editor.getTextInBufferRange.mockImplementation(() => formattedFixture);
});
it("does not change the text in the editor's buffer range",
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it("does not change the text in the editor's buffer range", /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const before = editor.getTextInBufferRange(bufferRangeFixture);
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
const after = editor.getTextInBufferRange(bufferRangeFixture);
Expand All @@ -201,9 +183,7 @@ describe('when text in buffer range is already pretty', () => {
// this test.
// expect(editor.setTextInBufferRange).not.toHaveBeenCalled();
}));
it("does not change the editor's cursor position",
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it("does not change the editor's cursor position", /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(editor.setCursorScreenPosition).not.toHaveBeenCalled();
}));
Expand All @@ -220,25 +200,19 @@ describe('when prettier throws an error', () => {
throw error;
});
});
it('handles the error',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('handles the error', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(handleError).toHaveBeenCalledWith({
editor,
error,
bufferRange: bufferRangeFixture
});
}));
it("does not change the text in the editor's buffer range",
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it("does not change the text in the editor's buffer range", /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(editor.setTextInBufferRange).not.toHaveBeenCalled();
}));
it("does not change the editor's cursor position",
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it("does not change the editor's cursor position", /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
yield executePrettierOnBufferRange(editor, bufferRangeFixture);
expect(editor.setCursorScreenPosition).not.toHaveBeenCalled();
}));
Expand Down
20 changes: 5 additions & 15 deletions dist/formatOnSave/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@ const shouldFormatOnSave = require('./shouldFormatOnSave');

const formatOnSave = require('./index');

it('returns a Promise',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('returns a Promise', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const editor = createMockTextEditor();
const result = formatOnSave(editor);
expect(result).toBeInstanceOf(Promise);
}));
it('clears linter errors before running',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('clears linter errors before running', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const editor = createMockTextEditor();
yield formatOnSave(editor);
expect(clearLinterErrors).toHaveBeenCalledWith(editor);
}));
it('executes prettier on the buffer range if appropriate and scope is not embedded',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('executes prettier on the buffer range if appropriate and scope is not embedded', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const editor = createMockTextEditor();
const mockRange = {
start: [0, 0],
Expand All @@ -56,18 +50,14 @@ it('executes prettier on the buffer range if appropriate and scope is not embedd
setTextViaDiff: true
});
}));
it('does nothing if it should not format on save',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('does nothing if it should not format on save', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const editor = createMockTextEditor();
shouldFormatOnSave.mockImplementation(() => false);
yield formatOnSave(editor);
expect(shouldFormatOnSave).toHaveBeenCalledWith(editor);
expect(executePrettierOnBufferRange).not.toHaveBeenCalled();
}));
it('catches uncaught errors so that the user is not prevented from saving',
/*#__PURE__*/
(0, _asyncToGenerator2["default"])(function* () {
it('catches uncaught errors so that the user is not prevented from saving', /*#__PURE__*/(0, _asyncToGenerator2["default"])(function* () {
const originalConsoleError = console.error; // eslint-disable-line no-console

console.error = jest.fn(); // eslint-disable-line no-console
Expand Down
2 changes: 1 addition & 1 deletion dist/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

const getPrettierInstance = require('./getPrettierInstance');

Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
"atom-package-deps": "^5.1.0",
"atom-text-buffer-point": "^1.0.0",
"atom-text-buffer-range": "^1.0.0",
"execa": "^1.0.0",
"execa": "^4.0.0",
"global-modules": "^2.0.0",
"ignore": "^5.1.4",
"lodash": "^4.17.13",
"loophole": "^1.1.0",
"prettier": "1.18.2",
"prettier": "2.0.2",
"prettier-stylelint": "^0.4.2",
"read-pkg-up": "^6.0.0",
"read-pkg-up": "^7.0.1",
"yarn-global-modules": "^1.0.1"
},
"devDependencies": {
Expand All @@ -51,7 +51,7 @@
"conventional-changelog-cli": "^2.0.31",
"cz-conventional-changelog": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.20.2",
Expand All @@ -69,8 +69,12 @@
},
"scripts": {
"start": "nps",
"test": "nps test",
"precommit": "opt --in pre-commit --exec \"npm start validate\""
"test": "nps test"
},
"husky": {
"hooks": {
"pre-commit": "opt --in pre-commit --exec \"npm start validate\""
}
},
"config": {
"commitizen": {
Expand Down
12 changes: 3 additions & 9 deletions src/atomInterface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const setConfigOption = (key: string, value: any) => atom.config.set(`prettier-a
const isLinterLintCommandDefined = (editor: TextEditor) =>
atom.commands
.findCommands({ target: atom.views.getView(editor) })
.some(command => command.name === LINTER_LINT_COMMAND);
.some((command) => command.name === LINTER_LINT_COMMAND);

// public
const isLinterEslintAutofixEnabled = () =>
Expand Down Expand Up @@ -74,21 +74,15 @@ const runLinter = (editor: TextEditor) =>
atom.commands.dispatch(atom.views.getView(editor), LINTER_LINT_COMMAND);

const invokeAtomRelativizePath = _.flow(
filePath => atom.project.relativizePath(filePath), // NOTE: fat arrow necessary for `this`
(filePath) => atom.project.relativizePath(filePath), // NOTE: fat arrow necessary for `this`
_.get('[1]'),
);

const relativizePathToDirname = (filePath: string) => path.relative(path.dirname(filePath), filePath);

const relativizePathFromAtomProject: (filePath: ?string) => ?string = _.cond([
[_.isNil, _.constant(null)],
[
_.flow(
invokeAtomRelativizePath,
path.isAbsolute,
),
relativizePathToDirname,
],
[_.flow(invokeAtomRelativizePath, path.isAbsolute), relativizePathToDirname],
[_.stubTrue, invokeAtomRelativizePath],
]);

Expand Down
2 changes: 1 addition & 1 deletion src/editorInterface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getCurrentFilePath = (editor: TextEditor): ?FilePath =>

const isCurrentFilePathDefined = (editor: ?TextEditor) => editor && !!getCurrentFilePath(editor);

const getCurrentDir: (editor: TextEditor) => ?string = editor =>
const getCurrentDir: (editor: TextEditor) => ?string = (editor) =>
lazyFlow()(getCurrentFilePath, (maybeFilePath: ?string) =>
typeof maybeFilePath === 'string' ? path.dirname(maybeFilePath) : undefined,
)(editor);
Expand Down
20 changes: 7 additions & 13 deletions src/executePrettier/handleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,18 @@ const setErrorMessageInLinter = ({ editor, bufferRange, error }: HandleErrorArgs
},
]);

const isSyntaxError: HandleErrorArgs => boolean = _.overSome([
_.flow(
_.get('error.loc.start.line'),
_.isInteger,
),
_.flow(
_.get('error.loc.line'),
_.isInteger,
),
const isSyntaxError: (HandleErrorArgs) => boolean = _.overSome([
_.flow(_.get('error.loc.start.line'), _.isInteger),
_.flow(_.get('error.loc.line'), _.isInteger),
]);

const isUndefinedError: HandleErrorArgs => boolean = _.flow(
const isUndefinedError: (HandleErrorArgs) => boolean = _.flow(
_.get('error.message'),
// $FlowIssue
_.matches('undefined'),
);

const isFilePathPresent: HandleErrorArgs => boolean = _.flow(
const isFilePathPresent: (HandleErrorArgs) => boolean = _.flow(
_.get('editor'),
getCurrentFilePath,
_.negate(_.isNil),
Expand All @@ -71,10 +65,10 @@ const displayErrorInPopup = (args: HandleErrorArgs) =>
dismissable: true,
});

const handleError: HandleErrorArgs => void = _.flow(
const handleError: (HandleErrorArgs) => void = _.flow(
_.cond([
[_.overEvery([isSyntaxError, isFilePathPresent]), setErrorMessageInLinter],
[isUndefinedError, args => console.error('Prettier encountered an error:', args.error)], // eslint-disable-line no-console
[isUndefinedError, (args) => console.error('Prettier encountered an error:', args.error)], // eslint-disable-line no-console
[_.stubTrue, displayErrorInPopup],
]),
);
Expand Down
Loading