Skip to content

Commit 200057d

Browse files
committed
eslint, simple fixes
1 parent 505d141 commit 200057d

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

cli/asconfig.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const overrides = {
4444
cliOptions.options.optimizeLevel = asconfigOptions.optimizeLevel;
4545
}
4646
},
47-
}
47+
};
4848

4949
function getASConfig(asconfigPath, targetName, readFile, configuration, cliOptions, required) {
5050
// calculate the directory and collect the asconfig
@@ -54,26 +54,26 @@ function getASConfig(asconfigPath, targetName, readFile, configuration, cliOptio
5454

5555
// if no asconfig exists
5656
if (!contents) {
57-
assert(!required, "No config was found at " + asconfigPath);
58-
return;
57+
if (required) throw new Error("No config was found at " + asconfigPath);
58+
else return;
5959
}
6060

6161
// validate here
6262
const config = validate(contents, configuration);
6363

6464
// resolve each parent configuration first
65-
if (config.extends) {
66-
getASConfig(
67-
path.isAbsolute(config.extends)
68-
? config.extends
69-
: path.resolve(path.dirname(asconfigPath), config.extends),
70-
targetName,
71-
readFile,
72-
configuration,
73-
cliOptions,
74-
true
75-
);
76-
}
65+
// if (config.extends) {
66+
// getASConfig(
67+
// path.isAbsolute(config.extends)
68+
// ? config.extends
69+
// : path.resolve(path.dirname(asconfigPath), config.extends),
70+
// targetName,
71+
// readFile,
72+
// configuration,
73+
// cliOptions,
74+
// true
75+
// );
76+
// }
7777

7878
// if no options are provided in the configuration, return early
7979
if (!config.options) return;
@@ -103,42 +103,42 @@ exports.getASConfig = getASConfig;
103103
function validateOptionsObject(options, configDefinition) {
104104
for (const key of Object.keys(configDefinition)) {
105105
const type = configDefinition[key].type;
106-
if (!options.hasOwnProperty(key)) continue;
106+
if (!(key in options)) continue;
107107
switch (type) {
108108
case "b": {
109-
assert(typeof options[key] === "boolean", "Invalid configuration option " + key + ", must be a boolean.");
109+
if (typeof options[key] !== "boolean") throw new Error("Invalid configuration option " + key + ", must be a boolean.");
110110
break;
111111
}
112112
case "f": {
113-
assert(typeof options[key] === "number", "Invalid configuration option " + key + ", must be a number.");
113+
if (typeof options[key] !== "number") throw new Error("Invalid configuration option " + key + ", must be a number.");
114114
break;
115115
}
116116
case "F": {
117-
assert(Array.isArray(options[key]), "Invalid configuration option " + key + ", must be an array.");
117+
if (!Array.isArray(options[key])) throw new Error("Invalid configuration option " + key + ", must be an array.");
118118
for (const value of options[key]) {
119-
assert(typeof value === "number", "Invalid configuration value in option " + key + ", " + value + " must be a number.");
119+
if (typeof value !== "number") throw new Error("Invalid configuration value in option " + key + ", " + value + " must be a number.");
120120
}
121121
break;
122122
}
123123
case "i": {
124-
assert(Number.isInteger(options[key]), "Invalid configuration option " + key + ", must be an integer.");
124+
if (!Number.isInteger(options[key])) throw new Error("Invalid configuration option " + key + ", must be an integer.");
125125
break;
126126
}
127127
case "I": {
128-
assert(Array.isArray(options[key]), "Invalid configuration option " + key + ", must be an array.");
128+
if (!Array.isArray(options[key])) throw new Error("Invalid configuration option " + key + ", must be an array.");
129129
for (const value of options[key]) {
130-
assert(Number.isInteger(value), "Invalid configuration value in option " + key + ", " + value + " must be an integer.");
130+
if (!Number.isInteger(value)) throw new Error("Invalid configuration value in option " + key + ", " + value + " must be an integer.");
131131
}
132132
break;
133133
}
134134
case "s": {
135-
assert(typeof options[key] === "string", "Invalid configuration option " + key + ", must be a string.");
135+
if (typeof options[key] !== "string") throw new Error("Invalid configuration option " + key + ", must be a string.");
136136
break;
137137
}
138138
case "S": {
139-
assert(Array.isArray(options[key]), "Invalid configuration option " + key + ", must be an array.");
139+
if (!Array.isArray(options[key])) throw new Error("Invalid configuration option " + key + ", must be an array.");
140140
for (const value of options[key]) {
141-
assert(typeof value === "string", "Invalid configuration value in option " + key + ", " + value + " must be a string.");
141+
if (typeof value !== "string") throw new Error("Invalid configuration option " + key + ", must be a string.");
142142
}
143143
break;
144144
}
@@ -150,22 +150,23 @@ function validateOptionsObject(options, configDefinition) {
150150
function validate(contents, configDefinition) {
151151
let config;
152152
try {
153-
config = assert(JSON.parse(contents), "Configuration must be an object.");
154-
if (config.extends) {
155-
assert(typeof config.extends === "string", "Configuration extends value must be a string.");
156-
assert(path.extname(config.extends) === ".json", "Configuration must extend a json file.");
157-
}
153+
config = JSON.parse(contents);
154+
if (!config) throw new Error("Configuration must be an object.");
155+
// if (config.extends) {
156+
// if (typeof config.extends !== "string") throw new Error("Configuration extends value must be a string.");
157+
// if (path.extname(config.extends) !== ".json") throw new Error( "Configuration must extend a json file.");
158+
// }
158159
if (config.targets) {
159-
assert(Array.isArray(config.targets), "Configuration targets value must be an Array.");
160+
if (!Array.isArray(config.targets)) throw new Error("Configuration targets value must be an Array.");
160161
config.targets.forEach(target => {
161-
assert(typeof target.name === "string", "All configuration targets must have a name.");
162+
if (typeof target.name !== "string") throw new Error("All configuration targets must have a name.");
162163
});
163164
}
164165

165166
// validate the options object
166167
if (config.options) {
167168
const options = config.options;
168-
assert(typeof options === "object", "Configuration options must be an object.");
169+
if (typeof options !== "object") throw new Error("Configuration options must be an object.");
169170
validateOptionsObject(options, configDefinition);
170171
}
171172

@@ -174,17 +175,17 @@ function validate(contents, configDefinition) {
174175

175176
// targets must be an array
176177
const targets = config.targets;
177-
assert(typeof targets === "object", "Configuration property 'targets' must be an object.");
178+
if (typeof targets !== "object") throw new Error("Configuration property 'targets' must be an object.");
178179
for (const targetName of Object.keys(targets)) {
179180
const target = targets[targetName];
180181

181182
// each target must be an object with a name and an options
182-
assert(typeof target === "object", "Configuration target '" + targetName + "' must be an object.");
183-
validateOptionsObject(options, configDefinition);
183+
if (typeof target !== "object") throw new Error("Configuration target '" + targetName + "' must be an object.");
184+
validateOptionsObject(target, configDefinition);
184185
}
185186
}
186187
} catch(ex) {
187-
throw new Error("Invalid asconfig at location " + asconfigPath + ": " + ex.message);
188+
throw new Error("Invalid asconfig: " + ex.message);
188189
}
189190
return config;
190191
}
@@ -222,4 +223,5 @@ function reconcile(cliOptions, asconfigOptions, asconfig, overrides) {
222223
}
223224
}
224225
}
226+
225227
exports.reconcile = reconcile;

cli/util/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function parse(argv, config) {
8888
}
8989
while (i < k) trailing.push(argv[i++]); // trailing
9090

91-
return { options, unknown, arguments, trailing, provides };
91+
return { options, unknown, arguments: args, trailing, provides };
9292
}
9393

9494
exports.parse = parse;

tests/parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var tests = glob.sync("**/!(_*).ts", { cwd: basedir });
4242

4343
// Run specific tests only if arguments are provided
4444
if (argv.length) {
45+
console.log(argv);
4546
tests = tests.filter(filename => argv.indexOf(filename.replace(/\.ts$/, "")) >= 0);
4647
if (!tests.length) {
4748
console.error("No matching tests: " + argv.join(" "));

0 commit comments

Comments
 (0)