Skip to content

Commit 26b5e53

Browse files
committed
fix: remove guards because of workingDirectory
1 parent b5f3da3 commit 26b5e53

File tree

4 files changed

+14
-59
lines changed

4 files changed

+14
-59
lines changed

lib/grammar-utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ const GrammarUtils = {
6161
return ["-c", command]
6262
},
6363

64+
/** get workingDirectory */
65+
workingDirectory() {
66+
const activePane = atom.workspace.getActivePaneItem()
67+
if (activePane && activePane.buffer && activePane.buffer.file && activePane.buffer.file.getParent) {
68+
const parent = activePane.buffer.file.getParent()
69+
if (parent && parent.getPath) {
70+
return parent.getPath()
71+
}
72+
}
73+
return process.cwd()
74+
},
75+
6476
// Public: Get the Java helper object
6577
//
6678
// Returns an {Object} which assists in preparing java + javac statements

lib/grammars/c.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
"use babel"
22

3-
/*
4-
* decaffeinate suggestions:
5-
* DS102: Remove unnecessary code created because of implicit returns
6-
* DS205: Consider reworking code to avoid use of IIFEs
7-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
8-
*/
93
import path from "path"
104
import GrammarUtils from "../grammar-utils"
115
const { OperatingSystem, command } = GrammarUtils

lib/grammars/doc.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
"use babel"
22

3-
/*
4-
* decaffeinate suggestions:
5-
* DS102: Remove unnecessary code created because of implicit returns
6-
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
7-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
8-
*/
93
import { shell } from "electron"
104
import GrammarUtils from "../grammar-utils"
115

@@ -30,18 +24,7 @@ const DOT = {
3024
const gnuplot = {
3125
"File Based": {
3226
command: "gnuplot",
33-
workingDirectory: __guardMethod__(
34-
__guardMethod__(
35-
__guard__(
36-
__guard__(atom.workspace.getActivePaneItem(), (x1) => x1.buffer),
37-
(x) => x.file
38-
),
39-
"getParent",
40-
(o1) => o1.getParent()
41-
),
42-
"getPath",
43-
(o) => o.getPath()
44-
),
27+
workingDirectory: GrammarUtils.workingDirectory(),
4528
args({ filepath }) {
4629
return ["-p", filepath]
4730
},
@@ -117,17 +100,6 @@ const Sass = {
117100

118101
const SCSS = Sass
119102

120-
function __guardMethod__(obj, methodName, transform) {
121-
if (typeof obj !== "undefined" && obj !== null && typeof obj[methodName] === "function") {
122-
return transform(obj, methodName)
123-
} else {
124-
return undefined
125-
}
126-
}
127-
function __guard__(value, transform) {
128-
return typeof value !== "undefined" && value !== null ? transform(value) : undefined
129-
}
130-
131103
const Docs = {
132104
DOT,
133105
GNUPlot: gnuplot,

lib/grammars/index.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/*
44
* decaffeinate suggestions:
55
* DS102: Remove unnecessary code created because of implicit returns
6-
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
76
* DS205: Consider reworking code to avoid use of IIFEs
87
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
98
*/
@@ -153,18 +152,7 @@ const OtherGrammars = {
153152
Go: {
154153
"File Based": {
155154
command: "go",
156-
workingDirectory: __guardMethod__(
157-
__guardMethod__(
158-
__guard__(
159-
__guard__(atom.workspace.getActivePaneItem(), (x1) => x1.buffer),
160-
(x) => x.file
161-
),
162-
"getParent",
163-
(o1) => o1.getParent()
164-
),
165-
"getPath",
166-
(o) => o.getPath()
167-
),
155+
workingDirectory: GrammarUtils.workingDirectory(),
168156
args({ filepath }) {
169157
if (filepath.match(/_test.go/)) {
170158
return ["test", ""]
@@ -611,14 +599,3 @@ const OtherGrammars = {
611599
},
612600
}
613601
export default OtherGrammars
614-
615-
function __guardMethod__(obj, methodName, transform) {
616-
if (typeof obj !== "undefined" && obj !== null && typeof obj[methodName] === "function") {
617-
return transform(obj, methodName)
618-
} else {
619-
return undefined
620-
}
621-
}
622-
function __guard__(value, transform) {
623-
return typeof value !== "undefined" && value !== null ? transform(value) : undefined
624-
}

0 commit comments

Comments
 (0)