Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 1edaaaf

Browse files
authored
Decaffinate project into Javascript (#344)
- Added Prettier to give a baseline for formatting. - Added Husky to ensure consistency with formatting.
1 parent 3759f7e commit 1edaaaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2740
-1949
lines changed

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.cache
2+
package.json
3+
package-lock.json
4+
public
5+
__generated__
6+
gen
7+
apollo.config.js
8+
schema.json

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"endOfLine": "lf",
3+
"semi": true,
4+
"singleQuote": true,
5+
"tabWidth": 4,
6+
"trailingComma": "es5"
7+
}

PLUGINS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The `spell-check` allows for additional dictionaries to be used at the same time
1313
The `nameOfFunctionToProvideSpellCheck` function may return either a single `require`able path or an array of them. This must be an absolute path to a class that provides a checker instance (below).
1414

1515
provideSpellCheck: ->
16-
require.resolve './project-checker.coffee'
16+
require.resolve './project-checker'
1717

1818
The path given must either resolve to a singleton instance of a class or a default export in a ES6 module.
1919

coffeelint.json

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/checker-env.coffee

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/checker-env.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
isLinux() {
3+
return /linux/.test(process.platform);
4+
},
5+
isWindows() {
6+
return /win32/.test(process.platform);
7+
}, // TODO: Windows < 8 or >= 8
8+
isDarwin() {
9+
return /darwin/.test(process.platform);
10+
},
11+
preferHunspell() {
12+
return !!process.env.SPELLCHECKER_PREFER_HUNSPELL;
13+
},
14+
15+
isSystemSupported() {
16+
return this.isWindows() || this.isDarwin();
17+
},
18+
isLocaleSupported() {
19+
return true;
20+
},
21+
22+
useLocales() {
23+
return this.isLinux() || this.isWindows() || this.preferHunspell();
24+
},
25+
};

lib/corrections-view.js

Lines changed: 93 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,102 @@
11
/** @babel */
22

3-
import SelectListView from 'atom-select-list'
3+
import SelectListView from 'atom-select-list';
44

55
export default class CorrectionsView {
6-
constructor (editor, corrections, marker, updateTarget, updateCallback) {
7-
this.editor = editor
8-
this.corrections = corrections
9-
this.marker = marker
10-
this.updateTarget = updateTarget
11-
this.updateCallback = updateCallback
12-
this.selectListView = new SelectListView({
13-
emptyMessage: 'No corrections',
14-
items: this.corrections,
15-
filterKeyForItem: (item) => item.label,
16-
elementForItem: (item) => {
17-
const element = document.createElement('li')
18-
if (item.isSuggestion) {
19-
// This is a word replacement suggestion.
20-
element.textContent = item.label
21-
} else {
22-
// This is an operation such as add word.
23-
const em = document.createElement('em')
24-
em.textContent = item.label
25-
element.appendChild(em)
26-
}
27-
return element
28-
},
29-
didConfirmSelection: (item) => {
30-
this.editor.transact(() => {
31-
if (item.isSuggestion) {
32-
// Update the buffer with the correction.
33-
this.editor.setSelectedBufferRange(this.marker.getBufferRange())
34-
this.editor.insertText(item.suggestion)
35-
} else {
36-
// Build up the arguments object for this buffer and text.
37-
let projectPath = null
38-
let relativePath = null
39-
if (this.editor && this.editor.buffer && this.editor.buffer.file && this.editor.buffer.file.path) {
40-
[projectPath, relativePath] = atom.project.relativizePath(this.editor.buffer.file.path)
41-
}
6+
constructor(editor, corrections, marker, updateTarget, updateCallback) {
7+
this.editor = editor;
8+
this.corrections = corrections;
9+
this.marker = marker;
10+
this.updateTarget = updateTarget;
11+
this.updateCallback = updateCallback;
12+
this.selectListView = new SelectListView({
13+
emptyMessage: 'No corrections',
14+
items: this.corrections,
15+
filterKeyForItem: (item) => item.label,
16+
elementForItem: (item) => {
17+
const element = document.createElement('li');
18+
if (item.isSuggestion) {
19+
// This is a word replacement suggestion.
20+
element.textContent = item.label;
21+
} else {
22+
// This is an operation such as add word.
23+
const em = document.createElement('em');
24+
em.textContent = item.label;
25+
element.appendChild(em);
26+
}
27+
return element;
28+
},
29+
didConfirmSelection: (item) => {
30+
this.editor.transact(() => {
31+
if (item.isSuggestion) {
32+
// Update the buffer with the correction.
33+
this.editor.setSelectedBufferRange(
34+
this.marker.getBufferRange()
35+
);
36+
this.editor.insertText(item.suggestion);
37+
} else {
38+
// Build up the arguments object for this buffer and text.
39+
let projectPath = null;
40+
let relativePath = null;
41+
if (
42+
this.editor &&
43+
this.editor.buffer &&
44+
this.editor.buffer.file &&
45+
this.editor.buffer.file.path
46+
) {
47+
[
48+
projectPath,
49+
relativePath,
50+
] = atom.project.relativizePath(
51+
this.editor.buffer.file.path
52+
);
53+
}
4254

43-
const args = {id: this.id, projectPath, relativePath}
44-
// Send the "add" request to the plugin.
45-
item.plugin.add(args, item)
46-
// Update the buffer to handle the corrections.
47-
this.updateCallback.bind(this.updateTarget)()
48-
}
49-
})
50-
this.destroy()
51-
},
52-
didConfirmEmptySelection: () => {
53-
this.destroy()
54-
},
55-
didCancelSelection: () => {
56-
this.destroy()
57-
}
58-
})
59-
this.selectListView.element.classList.add('spell-check-corrections', 'corrections', 'popover-list')
60-
}
55+
const args = { id: this.id, projectPath, relativePath };
56+
// Send the "add" request to the plugin.
57+
item.plugin.add(args, item);
58+
// Update the buffer to handle the corrections.
59+
this.updateCallback.bind(this.updateTarget)();
60+
}
61+
});
62+
this.destroy();
63+
},
64+
didConfirmEmptySelection: () => {
65+
this.destroy();
66+
},
67+
didCancelSelection: () => {
68+
this.destroy();
69+
},
70+
});
71+
this.selectListView.element.classList.add(
72+
'spell-check-corrections',
73+
'corrections',
74+
'popover-list'
75+
);
76+
}
6177

62-
attach () {
63-
this.previouslyFocusedElement = document.activeElement
64-
this.overlayDecoration = this.editor.decorateMarker(this.marker, {type: 'overlay', item: this.selectListView})
65-
process.nextTick(() => {
66-
atom.views.readDocument(() => { this.selectListView.focus() })
67-
})
68-
}
78+
attach() {
79+
this.previouslyFocusedElement = document.activeElement;
80+
this.overlayDecoration = this.editor.decorateMarker(this.marker, {
81+
type: 'overlay',
82+
item: this.selectListView,
83+
});
84+
process.nextTick(() => {
85+
atom.views.readDocument(() => {
86+
this.selectListView.focus();
87+
});
88+
});
89+
}
6990

70-
async destroy () {
71-
if (!this.destroyed) {
72-
this.destroyed = true
73-
this.overlayDecoration.destroy()
74-
await this.selectListView.destroy()
75-
if (this.previouslyFocusedElement) {
76-
this.previouslyFocusedElement.focus()
77-
this.previouslyFocusedElement = null
78-
}
91+
async destroy() {
92+
if (!this.destroyed) {
93+
this.destroyed = true;
94+
this.overlayDecoration.destroy();
95+
await this.selectListView.destroy();
96+
if (this.previouslyFocusedElement) {
97+
this.previouslyFocusedElement.focus();
98+
this.previouslyFocusedElement = null;
99+
}
100+
}
79101
}
80-
}
81102
}

lib/known-words-checker.coffee

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)