8000 Minor refactoring in logger and pyconfig (#1072) · WilliamHackspeare/pyscript@4b840f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b840f7

Browse files
authored
Minor refactoring in logger and pyconfig (pyscript#1072)
1 parent f73d6cd commit 4b840f7

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pyscriptjs/src/logger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
logger.warn('...');
1111
logger.error('...');
1212
13-
The logger automatically adds the prefix "[my-prefix]" to all logs; so e.g., the
14-
above call would print:
13+
The logger automatically adds the prefix "[my-prefix]" to all logs.
14+
E.g., the above call would print:
1515
1616
[my-prefix] hello world
1717
@@ -42,7 +42,7 @@ function getLogger(prefix: string): Logger {
4242
}
4343

4444
function _makeLogger(prefix: string): Logger {
45-
prefix = '[' + prefix + '] ';
45+
prefix =`[${prefix}] `;
4646

4747
function make(level: string) {
4848
const out_fn = console[level].bind(console);

pyscriptjs/src/pyconfig.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function loadConfigFromElement(el: Element): AppConfig {
7575
srcConfig = mergeConfig(srcConfig, defaultConfig);
7676
const result = mergeConfig(inlineConfig, srcConfig);
7777
result.pyscript = {
78-
version: version,
78+
version,
7979
time: new Date().toISOString(),
8080
};
8181
return result;
@@ -140,7 +140,6 @@ function mergeConfig(inlineConfig: AppConfig, externalConfig: AppConfig): AppCon
140140
}
141141

142142
function parseConfig(configText: string, configType = 'toml') {
143-
let config: object;
144143
if (configType === 'toml') {
145144
try {
146145
// TOML parser is soft and can parse even JSON strings, this additional check prevents it.
@@ -150,7 +149,7 @@ function parseConfig(configText: string, configType = 'toml') {
150149
`The config supplied: ${configText} is an invalid TOML and cannot be parsed`
151150
);
152151
}
153-
config = toml.parse(configText);
152+
return toml.parse(configText);
154153
} catch (err) {
155154
const errMessage: string = err.toString();
156155
throw new UserError(
@@ -160,7 +159,7 @@ function parseConfig(configText: string, configType = 'toml') {
160159
}
161160
} else if (configType === 'json') {
162161
try {
163-
config = JSON.parse(configText);
162+
return JSON.parse(configText);
164163
} catch (err) {
165164
const errMessage: string = err.toString();
166165
throw new UserError(
@@ -174,7 +173,6 @@ function parseConfig(configText: string, configType = 'toml') {
174173
`The type of config supplied '${configType}' is not supported, supported values are ["toml", "json"]`
175174
);
176175
}
177-
return config;
178176
}
179177

180178
function validateConfig(configText: string, configType = 'toml') {

0 commit comments

Comments
 (0)
0