@sheplu/editorconfig 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  } from './src/templates/index.js';
12
12
  import { loadCustomTemplate } from './src/templates/custom-template.js';
13
13
  import { compareEditorConfig, NO_LANGUAGE_FILTER, runCheck } from './src/check.js';
14
+ import { logger } from './src/utils/logger.js';
14
15
 
15
16
  export { compareEditorConfig };
16
17
 
@@ -74,7 +75,7 @@ function formatAliasList() {
74
75
  }
75
76
 
76
77
  export function printHelp() {
77
- console.log(`Usage: editorconfig --mode=<command> [--path=<path>] [--languages=<list>] [--template=<path|url>]
78
+ logger.log(`Usage: editorconfig --mode=<command> [--path=<path>] [--languages=<list>] [--template=<path|url>]
78
79
 
79
80
  Commands:
80
81
  write Create a .editorconfig file with the selected language sections
@@ -124,7 +125,7 @@ function promptLanguages() {
124
125
  const numbered = AVAILABLE_LANGUAGES
125
126
  .map((name, index) => ` ${index + 1}. ${name}`)
126
127
  .join('\n');
127
- console.log(`Available language sections:\n${numbered}`);
128
+ logger.log(`Available language sections:\n${numbered}`);
128
129
  rl.question('Languages? [comma-separated names or indices, blank=base only] ', (answer) => {
129
130
  rl.close();
130
131
  resolve(resolvePromptAnswer(answer));
@@ -154,7 +155,7 @@ function confirmOverwrite(path) {
154
155
 
155
156
  async function handleExistingTarget(path, languages, overrides) {
156
157
  if (!process.stdin.isTTY) {
157
- console.error(`\`${path}\` already exists. Use --overwrite to replace it.`);
158
+ logger.error(`\`${path}\` already exists. Use --overwrite to replace it.`);
158
159
  process.exitCode = 1;
159
160
  return;
160
161
  }
@@ -163,7 +164,7 @@ async function handleExistingTarget(path, languages, overrides) {
163
164
  createEditorConfig(path, languages, overrides);
164
165
  }
165
166
  else {
166
- console.log(`Skipped: \`${path}\` was not modified.`);
167
+ logger.log(`Skipped: \`${path}\` was not modified.`);
167
168
  }
168
169
  }
169
170
 
@@ -185,7 +186,7 @@ function dispatchCheck({ path, languages, strict, overrides }) {
185
186
  runCheck({ path, parsedLanguages: filter, strict, overrides });
186
187
  }
187
188
  catch (error) {
188
- console.error(error.message);
189
+ logger.error(error.message);
189
190
  process.exitCode = 1;
190
191
  }
191
192
  }
@@ -195,7 +196,7 @@ async function dispatchWrite({ path, overwrite, languages, overrides }) {
195
196
  await runWrite({ path, overwrite, parsedLanguages: languages, overrides });
196
197
  }
197
198
  catch (error) {
198
- console.error(error.message);
199
+ logger.error(error.message);
199
200
  process.exitCode = 1;
200
201
  }
201
202
  }
@@ -209,7 +210,7 @@ async function runCommand({ mode, path, overwrite, languages, strict, overrides
209
210
  dispatchCheck({ path, languages, strict, overrides });
210
211
  return;
211
212
  }
212
- console.error('invalid command');
213
+ logger.error('invalid command');
213
214
  process.exitCode = 1;
214
215
  }
215
216
 
@@ -225,7 +226,7 @@ function parseCliArgs(args) {
225
226
  return parseArgs({ args, options });
226
227
  }
227
228
  catch (error) {
228
- console.error(formatCliError(error));
229
+ logger.error(formatCliError(error));
229
230
  process.exitCode = 1;
230
231
  return false;
231
232
  }
@@ -241,7 +242,7 @@ async function resolveOverrides(templateValue) {
241
242
  return await loadCustomTemplate(templateValue);
242
243
  }
243
244
  catch (error) {
244
- console.error(error.message);
245
+ logger.error(error.message);
245
246
  process.exitCode = 1;
246
247
  return OVERRIDES_FAILED;
247
248
  }
@@ -279,7 +280,7 @@ if (process.argv[1] === import.meta.filename) {
279
280
  await main();
280
281
  }
281
282
  catch (error) {
282
- console.error(error.message);
283
+ logger.error(error.message);
283
284
  process.exitCode = 1;
284
285
  }
285
286
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheplu/editorconfig",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -40,6 +40,6 @@
40
40
  "homepage": "https://github.com/sheplu/editorconfig#readme",
41
41
  "devDependencies": {
42
42
  "node-pty": "1.0.0",
43
- "oxlint": "^1.64.0"
43
+ "oxlint": "^1.65.0"
44
44
  }
45
45
  }
package/src/check.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  parseSections,
10
10
  resolveLanguageNames,
11
11
  } from './templates/index.js';
12
+ import { logger } from './utils/logger.js';
12
13
 
13
14
  export const NO_LANGUAGE_FILTER = Symbol('check-no-language-filter');
14
15
 
@@ -108,15 +109,15 @@ export function reportIsFailing({ baseIssues, results }, strict) {
108
109
  }
109
110
 
110
111
  function printReport(path, report) {
111
- console.log(`Checking ${path}`);
112
- console.log('');
112
+ logger.log(`Checking ${path}`);
113
+ logger.log('');
113
114
  for (const issue of report.baseIssues) {
114
- console.log(formatLine(issue));
115
+ logger.log(formatLine(issue));
115
116
  }
116
117
  for (const entry of report.results) {
117
- console.log(formatLine(entry));
118
+ logger.log(formatLine(entry));
118
119
  }
119
- console.log('');
120
+ logger.log('');
120
121
  }
121
122
 
122
123
  function summarize(report) {
@@ -168,7 +169,7 @@ export function runCheck({ path, parsedLanguages, strict, overrides }) {
168
169
  const report = compareEditorConfig(path, parsedLanguages, overrides);
169
170
  printReport(path, report);
170
171
  const failed = reportIsFailing(report, strict);
171
- console.log(formatSummary(report, failed));
172
+ logger.log(formatSummary(report, failed));
172
173
  if (failed) {
173
174
  process.exitCode = 1;
174
175
  }
@@ -1,15 +1,18 @@
1
1
  import { parseRedirectLocation } from './url.js';
2
2
 
3
3
  const TIMEOUT_MS = 10_000;
4
+ const MS_PER_SECOND = 1000;
4
5
  const MAX_BYTES = 1_048_576;
5
6
  const MAX_REDIRECTS = 5;
7
+ const HTTP_REDIRECT_MIN = 300;
8
+ const HTTP_REDIRECT_MAX = 400;
6
9
 
7
10
  function ignoreCancelError() {
8
11
  return false;
9
12
  }
10
13
 
11
14
  export function isRedirect(status) {
12
- return status >= 300 && status < 400;
15
+ return status >= HTTP_REDIRECT_MIN && status < HTTP_REDIRECT_MAX;
13
16
  }
14
17
 
15
18
  export function rejectOversized(url) {
@@ -81,7 +84,7 @@ export async function performFetch(initialUrl, signal) {
81
84
 
82
85
  export function describeFetchError(url, error) {
83
86
  if (error.name === 'AbortError') {
84
- return new Error(`failed to fetch '${url}': request timed out after ${TIMEOUT_MS / 1000}s`);
87
+ return new Error(`failed to fetch '${url}': request timed out after ${TIMEOUT_MS / MS_PER_SECOND}s`);
85
88
  }
86
89
  if (/^failed to fetch |^template body /u.test(error.message)) {
87
90
  return error;
@@ -0,0 +1,8 @@
1
+ /* eslint-disable no-console */
2
+ export const logger = {
3
+ log: (...args) => console.log(...args),
4
+ info: (...args) => console.info(...args),
5
+ warn: (...args) => console.warn(...args),
6
+ error: (...args) => console.error(...args),
7
+ debug: (...args) => console.debug(...args),
8
+ };