This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prettier): use Prettier to determine whether a file is formattable
Instead of relying on the user to supply prettier-atom with a whole list of Atom scopes for each Prettier parser type, we instead rely on the new getFileInfo method from Prettier and let Prettier tell us whether or not a file is parseable. This will make future parser support automatic as well as allow Prettier plugins to work. Unfortunately, because we rely on this new feature from Prettier, it will mean that users will be forced to upgrade their local Prettier versions to be compatible. BREAKING CHANGE: Because prettier-atom now relies on the new `getFileInfo` method recently added to Prettier, if you are having prettier-atom use a local version of Prettier instead of the version that is packaged with the plugin, you will need to manually update your project's local Prettier version.
- Loading branch information
Showing
24 changed files
with
153 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash/fp'); | ||
const getPrettierInstance = require('./getPrettierInstance'); | ||
const { getCurrentFilePath } = require('../editorInterface'); | ||
|
||
const isFileFormattable = editor => !!editor && !!getCurrentFilePath(editor) && _.flow(getCurrentFilePath, | ||
// $FlowFixMe: getFileInfo is not yet added to flow typed | ||
filePath => getPrettierInstance().getFileInfo(filePath, {}, '.prettierignore'), fileInfo => fileInfo.exists && !fileInfo.ignored && !!fileInfo.inferredParser)(editor); | ||
|
||
module.exports = isFileFormattable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
'use strict'; | ||
|
||
const { getCurrentScope } = require('../editorInterface'); | ||
const { getScopes } = require('../atomInterface'); | ||
const { isFileFormattable } = require('../helpers'); | ||
|
||
const updateStatusTileScope = (element, editor) => { | ||
// The editor can be undefined if there is no active editor (e.g. closed all tabs). | ||
// eslint-disable-next-line no-param-reassign | ||
element.dataset.prettierMatchScope = editor && getScopes().includes(getCurrentScope(editor)) ? 'true' : 'false'; | ||
element.dataset.prettierCanFormatFile = editor && isFileFormattable(editor) ? 'true' : 'false'; | ||
}; | ||
|
||
module.exports = updateStatusTileScope; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.