Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit cffa97a

Browse files
Add “ESLint: Fix file” context menu option
1 parent a336092 commit cffa97a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,29 @@ export default {
158158
this.clearESLintCache();
159159
}
160160
}
161+
}),
162+
163+
// Add item to editor context menu.
164+
atom.contextMenu.add({
165+
'atom-text-editor:not(.mini), .overlayer': [{
166+
label: 'ESLint Fix',
167+
command: 'linter-eslint-node:fix-file',
168+
shouldDisplay: (evt) => {
169+
const activeEditor = atom.workspace.getActiveTextEditor();
170+
if (!activeEditor) {
171+
return false;
172+
}
173+
// Black magic!
174+
// Compares the private component property of the active TextEditor
175+
// against the components of the elements
176+
const evtIsActiveEditor = evt.path.some((elem) => (
177+
// Atom v1.19.0+
178+
elem.component && activeEditor.component
179+
&& elem.component === activeEditor.component));
180+
// Only show if it was the active editor and it is a valid scope
181+
return evtIsActiveEditor && helpers.hasValidScope(activeEditor, Config.get('scopes'));
182+
}
183+
}]
161184
})
162185
);
163186

0 commit comments

Comments
 (0)