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

Commit

Permalink
Remove pointless dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Jul 10, 2019
1 parent 620a5a9 commit f5c43f5
Show file tree
Hide file tree
Showing 4 changed files with 1,208 additions and 1,767 deletions.
4 changes: 2 additions & 2 deletions commands/generate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs');
const path = require('path');
const pify = require('pify');
const {promisify} = require('util');

module.exports = () => {
let basePath = '';
Expand Down Expand Up @@ -55,7 +55,7 @@ insert_final_newline = ${ensureFinalNewline}
trim_trailing_whitespace = false
`;

pify(fs.writeFile)(configFile, ret, {flag: 'wx'}).then(() => {
promisify(fs.writeFile)(configFile, ret, {flag: 'wx'}).then(() => {
atom.notifications.addSuccess('.editorconfig file successfully generated', {
detail: 'An .editorconfig file was successfully generated in your project based on your current settings.'
});
Expand Down
77 changes: 65 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
'use strict';
const {CompositeDisposable, Disposable} = require('atom');
const importLazy = require('import-lazy')(require);
const generateConfig = require('./commands/generate-config.js');
const showState = require('./commands/show-state.js');
const fixFile = require('./commands/fix-file.js');

const editorconfig = importLazy('editorconfig');
const checklist = importLazy('./lib/checklist.js');
const wrapGuideInterceptor = importLazy('./lib/wrapguide-interceptor.js');
const statusTile = importLazy('./lib/statustile-view.js');
// Lazy-loaded modules
let checklist;
let editorconfig;
let fixFile;
let generateConfig;
let showState;
let statusTile;
let wrapGuideInterceptor;

// Sets the state of the embedded editorconfig
// This includes the severity (info, warning..) as well as the notification-messages for users
function setState(ecfg) {
if (!checklist) {
checklist = require('./lib/checklist.js');
}

checklist(ecfg);

if (!statusTile) {
statusTile = require('./lib/statustile-view.js');
}

statusTile.updateIcon(ecfg.state);
}

Expand Down Expand Up @@ -96,6 +105,10 @@ function initializeTextBuffer(buffer) {
const wrapGuide = bufferDom.querySelector('.wrap-guide');
if (wrapGuide !== null) {
if (wrapGuide.editorconfig === undefined) {
if (!wrapGuideInterceptor) {
wrapGuideInterceptor = require('./lib/wrapguide-interceptor.js');
}

wrapGuide.editorconfig = this;
wrapGuide.getNativeGuideColumn = wrapGuide.getGuideColumn;
wrapGuide.getGuideColumn = wrapGuideInterceptor.getGuideColumn.bind(wrapGuide);
Expand Down Expand Up @@ -268,6 +281,10 @@ function observeTextEditor(editor) {
return;
}

if (!editorconfig) {
editorconfig = require('editorconfig');
}

editorconfig.parse(file).then(config => {
if (Object.keys(config).length === 0) {
return;
Expand Down Expand Up @@ -342,6 +359,10 @@ function observeActivePaneItem(editor) {
editor.buffer.editorconfig.applySettings();
}
} else {
if (!statusTile) {
statusTile = require('./lib/statustile-view.js');
}

statusTile.removeIcon();
}
}
Expand All @@ -357,10 +378,34 @@ module.exports = {

this.disposables = new CompositeDisposable(
atom.commands.add('atom-workspace', {
'EditorConfig:fix-file': () => fixFile(),
'EditorConfig:fix-file-quietly': () => fixFile(false),
'EditorConfig:generate-config': () => generateConfig(),
'EditorConfig:show-state': () => showState()
'EditorConfig:fix-file': () => {
if (!fixFile) {
fixFile = require('./commands/fix-file.js');
}

return fixFile();
},
'EditorConfig:fix-file-quietly': () => {
if (!fixFile) {
fixFile = require('./commands/fix-file.js');
}

return fixFile(false);
},
'EditorConfig:generate-config': () => {
if (!generateConfig) {
generateConfig = require('./commands/generate-config.js');
}

return generateConfig();
},
'EditorConfig:show-state': () => {
if (!showState) {
showState = require('./commands/show-state.js');
}

return showState();
}
}),
atom.workspace.observeTextEditors(observeTextEditor),
atom.workspace.observeActivePaneItem(observeActivePaneItem),
Expand All @@ -369,6 +414,10 @@ module.exports = {
const textEditors = atom.workspace.getTextEditors();
textEditors.forEach(ed => ed.getBuffer().editorconfig.disposables.dispose());

if (!statusTile) {
statusTile = require('./lib/statustile-view.js');
}

// Clean the status-bar up
statusTile.removeIcon();
})
Expand Down Expand Up @@ -401,6 +450,10 @@ module.exports = {

// Apply the statusbar icon-container. The icon will be applied if needed
consumeStatusBar(statusBar) {
if (!statusTile) {
statusTile = require('./lib/statustile-view.js');
}

if (statusTile.containerExists() === false) {
statusBar.addRightTile({
item: statusTile.createContainer(),
Expand Down
Loading

0 comments on commit f5c43f5

Please sign in to comment.