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.
Merge pull request #165 from prettier/robwise/refactoring
Refactor
- Loading branch information
Showing
128 changed files
with
3,174 additions
and
2,332 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
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,123 @@ | ||
'use strict'; | ||
|
||
// constants | ||
var LINTER_LINT_COMMAND = 'linter:lint'; | ||
|
||
// local helpers | ||
var getConfigOption = function getConfigOption(key) { | ||
return atom.config.get('prettier-atom.' + key); | ||
}; | ||
|
||
var setConfigOption = function setConfigOption(key, value) { | ||
return atom.config.set('prettier-atom.' + key, value); | ||
}; | ||
|
||
var isLinterLintCommandDefined = function isLinterLintCommandDefined(editor) { | ||
return atom.commands.findCommands({ target: atom.views.getView(editor) }).some(function (command) { | ||
return command.name === LINTER_LINT_COMMAND; | ||
}); | ||
}; | ||
|
||
// public | ||
var isLinterEslintAutofixEnabled = function isLinterEslintAutofixEnabled() { | ||
return atom.config.get('linter-eslint.fixOnSave'); | ||
}; | ||
|
||
var shouldUseEslint = function shouldUseEslint() { | ||
return getConfigOption('useEslint'); | ||
}; | ||
|
||
var shouldUseEditorConfig = function shouldUseEditorConfig() { | ||
return getConfigOption('useEditorConfig'); | ||
}; | ||
|
||
var shouldDisplayErrors = function shouldDisplayErrors() { | ||
return !getConfigOption('silenceErrors'); | ||
}; | ||
|
||
var isFormatOnSaveEnabled = function isFormatOnSaveEnabled() { | ||
return getConfigOption('formatOnSaveOptions.enabled'); | ||
}; | ||
|
||
var shouldRespectEslintignore = function shouldRespectEslintignore() { | ||
return getConfigOption('formatOnSaveOptions.respectEslintignore'); | ||
}; | ||
|
||
var getScopes = function getScopes() { | ||
return getConfigOption('formatOnSaveOptions.scopes'); | ||
}; | ||
|
||
var getWhitelistedGlobs = function getWhitelistedGlobs() { | ||
return getConfigOption('formatOnSaveOptions.whitelistedGlobs'); | ||
}; | ||
|
||
var getExcludedGlobs = function getExcludedGlobs() { | ||
return getConfigOption('formatOnSaveOptions.excludedGlobs'); | ||
}; | ||
|
||
var toggleFormatOnSave = function toggleFormatOnSave() { | ||
return setConfigOption('formatOnSaveOptions.enabled', !isFormatOnSaveEnabled()); | ||
}; | ||
|
||
var getAtomTabLength = function getAtomTabLength(editor) { | ||
return atom.config.get('editor.tabLength', { scope: editor.getLastCursor().getScopeDescriptor() }); | ||
}; | ||
|
||
var getPrettierOptions = function getPrettierOptions() { | ||
return getConfigOption('prettierOptions'); | ||
}; | ||
|
||
var getPrettierEslintOptions = function getPrettierEslintOptions() { | ||
return getConfigOption('prettierEslintOptions'); | ||
}; | ||
|
||
var getAtomVersion = function getAtomVersion() { | ||
return atom.getVersion(); | ||
}; | ||
|
||
var getPrettierAtomConfig = function getPrettierAtomConfig() { | ||
return atom.config.get('prettier-atom'); | ||
}; | ||
|
||
var addTooltip = function addTooltip(element, options) { | ||
return atom.tooltips.add(element, options); | ||
}; | ||
|
||
var addInfoNotification = function addInfoNotification(message, options) { | ||
return atom.notifications.addInfo(message, options); | ||
}; | ||
|
||
var addWarningNotification = function addWarningNotification(message, options) { | ||
return atom.notifications.addWarning(message, options); | ||
}; | ||
|
||
var addErrorNotification = function addErrorNotification(message, options) { | ||
return atom.notifications.addError(message, options); | ||
}; | ||
|
||
var runLinter = function runLinter(editor) { | ||
return isLinterLintCommandDefined(editor) && atom.commands.dispatch(atom.views.getView(editor), LINTER_LINT_COMMAND); | ||
}; | ||
|
||
module.exports = { | ||
addErrorNotification: addErrorNotification, | ||
addInfoNotification: addInfoNotification, | ||
addTooltip: addTooltip, | ||
addWarningNotification: addWarningNotification, | ||
getAtomTabLength: getAtomTabLength, | ||
getAtomVersion: getAtomVersion, | ||
getExcludedGlobs: getExcludedGlobs, | ||
getPrettierAtomConfig: getPrettierAtomConfig, | ||
getPrettierEslintOptions: getPrettierEslintOptions, | ||
getPrettierOptions: getPrettierOptions, | ||
getScopes: getScopes, | ||
getWhitelistedGlobs: getWhitelistedGlobs, | ||
isFormatOnSaveEnabled: isFormatOnSaveEnabled, | ||
isLinterEslintAutofixEnabled: isLinterEslintAutofixEnabled, | ||
runLinter: runLinter, | ||
shouldDisplayErrors: shouldDisplayErrors, | ||
shouldRespectEslintignore: shouldRespectEslintignore, | ||
shouldUseEditorConfig: shouldUseEditorConfig, | ||
shouldUseEslint: shouldUseEslint, | ||
toggleFormatOnSave: toggleFormatOnSave | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
var readPkg = require('read-pkg'); | ||
var path = require('path'); | ||
|
||
var _require = require('../atomInterface'), | ||
getAtomVersion = _require.getAtomVersion, | ||
getPrettierAtomConfig = _require.getPrettierAtomConfig, | ||
addInfoNotification = _require.addInfoNotification; | ||
|
||
var getDepPath = function getDepPath(dep) { | ||
return path.join(__dirname, '..', '..', 'node_modules', dep); | ||
}; | ||
|
||
var getDebugInfo = function getDebugInfo() { | ||
return ('\nAtom version: ' + getAtomVersion() + '\nprettier-atom version: ' + readPkg.sync().version + '\nprettier version: ' + readPkg.sync(getDepPath('prettier')).version + '\nprettier-eslint version: ' + readPkg.sync(getDepPath('prettier-eslint')).version + '\nprettier-atom configuration: ' + JSON.stringify(getPrettierAtomConfig(), null, 2) + '\n').trim(); | ||
}; | ||
|
||
var displayDebugInfo = function displayDebugInfo() { | ||
return addInfoNotification('prettier-atom: details on current install', { | ||
detail: getDebugInfo(), | ||
dismissable: true | ||
}); | ||
}; | ||
|
||
module.exports = displayDebugInfo; |
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,26 @@ | ||
'use strict'; | ||
|
||
var EMBEDDED_SCOPES = ['text.html.vue', 'text.html.basic']; | ||
|
||
var getBufferRange = function getBufferRange(editor) { | ||
return editor.getBuffer().getRange(); | ||
}; | ||
|
||
var getCurrentScope = function getCurrentScope(editor) { | ||
return editor.getGrammar().scopeName; | ||
}; | ||
|
||
var isCurrentScopeEmbeddedScope = function isCurrentScopeEmbeddedScope(editor) { | ||
return EMBEDDED_SCOPES.includes(getCurrentScope(editor)); | ||
}; | ||
|
||
var getCurrentFilePath = function getCurrentFilePath(editor) { | ||
return editor.buffer.file ? editor.buffer.file.path : undefined; | ||
}; | ||
|
||
module.exports = { | ||
getBufferRange: getBufferRange, | ||
isCurrentScopeEmbeddedScope: isCurrentScopeEmbeddedScope, | ||
getCurrentScope: getCurrentScope, | ||
getCurrentFilePath: getCurrentFilePath | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
var _ = require('lodash/fp'); | ||
var editorconfig = require('editorconfig'); | ||
|
||
var maxLineLengthIsNumber = _.flow(_.get('max_line_length'), _.isNumber); | ||
|
||
var indentStyleIsTab = _.conforms({ indent_style: _.isEqual('tab') }); | ||
|
||
var indentSizeIsTab = _.conforms({ indent_size: _.isEqual('tab') }); | ||
|
||
var tabWidthIsNumber = _.conforms({ tab_width: _.isNumber }); | ||
|
||
var shouldUseTabWidth = _.overEvery([tabWidthIsNumber, _.overSome([indentSizeIsTab, indentStyleIsTab])]); | ||
|
||
var indentSizeIsNumber = _.conforms({ indent_size: _.isNumber }); | ||
|
||
var indentStyleIsSpace = _.conforms({ indent_style: _.isEqual('space') }); | ||
|
||
var getPrintWidth = _.cond([[maxLineLengthIsNumber, function (opts) { | ||
return { printWidth: opts.max_line_length }; | ||
}]]); | ||
|
||
var getTabWidth = _.cond([[shouldUseTabWidth, function (opts) { | ||
return { tabWidth: opts.tab_width }; | ||
}], [indentSizeIsNumber, function (opts) { | ||
return { tabWidth: opts.indent_size }; | ||
}]]); | ||
|
||
var getUseTabs = _.cond([[indentStyleIsTab, _.constant({ useTabs: true })], [indentStyleIsSpace, _.constant({ useTabs: false })]]); | ||
|
||
var mapEditorConfigOptions = function mapEditorConfigOptions() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return _extends({}, getPrintWidth(opts), getTabWidth(opts), getUseTabs(opts)); | ||
}; | ||
|
||
var buildEditorConfigOptions = _.flow(editorconfig.parseSync, mapEditorConfigOptions); | ||
|
||
module.exports = buildEditorConfigOptions; |
Oops, something went wrong.