@naturalcycles/dev-lib 20.70.0 → 20.71.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.
@@ -72,7 +72,7 @@ export const sharedConfig = {
72
72
  { blankLine: 'always', prev: '*', next: 'class' },
73
73
  ],
74
74
  '@stylistic/lines-between-class-members': [2, 'always', { exceptAfterSingleLine: true }],
75
- 'nc/prefer-assert': 0, // opt-in (set to 2): flags `if (cond) throw new Error(...)` that could be `_assert(...)`
75
+ 'nc/prefer-assert': 2,
76
76
  complexity: [2, { max: 40 }],
77
77
  'logical-assignment-operators': [
78
78
  2,
@@ -96,8 +96,10 @@ export const sharedConfig = {
96
96
  'object-shorthand': 2,
97
97
  'valid-expect': 0,
98
98
  'valid-title': 0,
99
- 'vitest/valid-title': 0,
99
+ 'vitest/valid-title': [2, { mustMatch: { it: '^should ' } }],
100
100
  'valid-describe-callback': 0,
101
+ // Options arguments and variables are `opt`, never `opts`
102
+ 'id-denylist': [2, 'opts'],
101
103
  // 'id-denylist': [
102
104
  // 0, // actually not useful
103
105
  // 'any',
@@ -146,6 +148,7 @@ export const sharedConfig = {
146
148
  name: 'Intl',
147
149
  message: 'Use Intl2 instead.',
148
150
  },
151
+ { name: 'Date', message: 'Use localTime / localDate from @naturalcycles/js-lib/datetime.' },
149
152
  ],
150
153
  'no-unused-expressions': 2,
151
154
  'no-var': 2,
@@ -462,13 +465,7 @@ export const sharedConfig = {
462
465
  'vitest/prefer-called-exactly-once-with': 2,
463
466
  'vitest/consistent-test-filename': 2,
464
467
  'vitest/warn-todo': 0,
465
- 'vitest/consistent-test-it': [
466
- 2,
467
- {
468
- fn: 'test',
469
- withinDescribe: 'test',
470
- },
471
- ],
468
+ 'vitest/consistent-test-it': [2, { fn: 'it', withinDescribe: 'it' }],
472
469
  'vitest/max-nested-describe': [0, { max: 4 }], // not good
473
470
  'vitest/no-alias-methods': 2,
474
471
  'vitest/no-restricted-vi-methods': [
@@ -4,6 +4,7 @@ import { findPackageJSON } from 'node:module';
4
4
  import path from 'node:path';
5
5
  import { _isTruthy } from '@naturalcycles/js-lib';
6
6
  import { _uniq } from '@naturalcycles/js-lib/array';
7
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/localTime.js';
7
8
  import { _since } from '@naturalcycles/js-lib/datetime/time.util.js';
8
9
  import { _assert } from '@naturalcycles/js-lib/error/assert.js';
9
10
  import { _filterFalsyValues } from '@naturalcycles/js-lib/object/object.util.js';
@@ -24,7 +25,7 @@ const { CI } = process.env;
24
25
  */
25
26
  export async function runCheck(opt = {}) {
26
27
  const { fastLinters = true, eslint = true, stylelint = true, oxfmt = true, ktlint = true, typecheck = false, test = true, } = opt;
27
- const started = Date.now();
28
+ const started = nowUnixMillis();
28
29
  let s;
29
30
  const timings = {};
30
31
  // const { commitOnChanges, failOnChanges } = _yargs().options({
@@ -49,52 +50,52 @@ export async function runCheck(opt = {}) {
49
50
  const fix = !CI;
50
51
  if (fastLinters) {
51
52
  // Fast linters (that run in <1 second) go first
52
- s = Date.now();
53
+ s = nowUnixMillis();
53
54
  if (runActionLint()) {
54
- timings['actionlint'] = Date.now() - s;
55
+ timings['actionlint'] = nowUnixMillis() - s;
55
56
  }
56
- s = Date.now();
57
+ s = nowUnixMillis();
57
58
  if (runOxlint(fix)) {
58
- timings['oxlint'] = Date.now() - s;
59
+ timings['oxlint'] = nowUnixMillis() - s;
59
60
  }
60
61
  }
61
62
  // From this point we start the "slow" linters, with ESLint leading the way
62
63
  if (eslint) {
63
64
  // We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
64
- s = Date.now();
65
+ s = nowUnixMillis();
65
66
  if (eslintAll({ fix })) {
66
- timings['eslint'] = Date.now() - s;
67
+ timings['eslint'] = nowUnixMillis() - s;
67
68
  }
68
69
  }
69
70
  if (stylelint &&
70
71
  hasDependencyInNodeModules('stylelint') &&
71
72
  hasDependencyInNodeModules('stylelint-config-standard-scss')) {
72
- s = Date.now();
73
+ s = nowUnixMillis();
73
74
  if (stylelintAll(fix)) {
74
- timings['stylelint'] = Date.now() - s;
75
+ timings['stylelint'] = nowUnixMillis() - s;
75
76
  }
76
77
  }
77
78
  if (oxfmt) {
78
- s = Date.now();
79
+ s = nowUnixMillis();
79
80
  if (runOxfmt(fix)) {
80
- timings['oxfmt'] = Date.now() - s;
81
+ timings['oxfmt'] = nowUnixMillis() - s;
81
82
  }
82
83
  }
83
84
  if (ktlint) {
84
- s = Date.now();
85
+ s = nowUnixMillis();
85
86
  if (await runKTLint(fix)) {
86
- timings['ktlint'] = Date.now() - s;
87
+ timings['ktlint'] = nowUnixMillis() - s;
87
88
  }
88
89
  }
89
90
  if (typecheck) {
90
- s = Date.now();
91
+ s = nowUnixMillis();
91
92
  await runTypecheck();
92
- timings['tsc'] = Date.now() - s;
93
+ timings['tsc'] = nowUnixMillis() - s;
93
94
  }
94
95
  if (test) {
95
- s = Date.now();
96
+ s = nowUnixMillis();
96
97
  if (runTest()) {
97
- timings['test'] = Date.now() - s;
98
+ timings['test'] = nowUnixMillis() - s;
98
99
  }
99
100
  }
100
101
  console.log(`${check(true)}${white(`check`)} ${dimGrey(`took ` + _since(started))}`);
@@ -1,3 +1,4 @@
1
+ import { localDate } from '@naturalcycles/js-lib/datetime/localDate.js';
1
2
  /**
2
3
  * Generate release notes markdown for a GitHub Release,
3
4
  * following the format of `@semantic-release/release-notes-generator` (angular preset):
@@ -5,7 +6,7 @@
5
6
  */
6
7
  export function generateReleaseNotes(input) {
7
8
  const { repo, commits, lastTag, nextTag } = input;
8
- const date = input.date || new Date().toISOString().slice(0, 10);
9
+ const date = input.date || localDate.todayInUTC().toISODate();
9
10
  const header = lastTag
10
11
  ? `## [${nextTag}](${repo.url}/compare/${lastTag}...${nextTag}) (${date})`
11
12
  : `## ${nextTag} (${date})`;
@@ -44,6 +44,7 @@ export const mockAllKindsOfThings = () => {
44
44
  k1: 'v1',
45
45
  }),
46
46
  Symbol('a_am_symbol'),
47
+ // oxlint-disable-next-line no-restricted-globals -- a native Date is one of the kinds of things
47
48
  new Date(1984, 5, 21),
48
49
  ];
49
50
  };
@@ -11,7 +11,7 @@ export interface BypassableSocket extends NetType.Socket {
11
11
  bypass: () => void;
12
12
  bypassed?: boolean;
13
13
  }
14
- export type ConnectCallback = (socket: BypassableSocket, opts: SocketOptions) => void;
14
+ export type ConnectCallback = (socket: BypassableSocket, opt: SocketOptions) => void;
15
15
  export interface Mitm {
16
16
  on: (event: 'connect', callback: ConnectCallback) => void;
17
17
  disable: () => void;
@@ -18,7 +18,7 @@ export function createMitm() {
18
18
  s[0][s[1]] = s[2];
19
19
  }
20
20
  }
21
- function connect(orig, opts, done) {
21
+ function connect(orig, opt, done) {
22
22
  // Create a bypassable socket that we'll pass to listeners
23
23
  const socket = new Net.Socket();
24
24
  socket.bypassed = false;
@@ -27,11 +27,11 @@ export function createMitm() {
27
27
  };
28
28
  // Emit connect event to all listeners
29
29
  for (const listener of listeners) {
30
- listener(socket, opts);
30
+ listener(socket, opt);
31
31
  }
32
32
  // If bypassed, call the original connect function
33
33
  if (socket.bypassed) {
34
- return orig.call(Net, opts, done);
34
+ return orig.call(Net, opt, done);
35
35
  }
36
36
  // Not bypassed - return the socket that will never actually connect.
37
37
  // testOffline throws an error before we get here, so this is just a fallback.
@@ -43,12 +43,12 @@ export function createMitm() {
43
43
  // connect(options, callback?)
44
44
  // connect(path, callback?) - Unix socket
45
45
  if (typeof args[0] === 'number') {
46
- const opts = { port: args[0] };
46
+ const opt = { port: args[0] };
47
47
  if (typeof args[1] === 'string') {
48
- opts.host = args[1];
49
- return [opts, args[2]];
48
+ opt.host = args[1];
49
+ return [opt, args[2]];
50
50
  }
51
- return [opts, args[1]];
51
+ return [opt, args[1]];
52
52
  }
53
53
  if (typeof args[0] === 'object' && args[0] !== null) {
54
54
  return [args[0], args[1]];
@@ -58,14 +58,14 @@ export function createMitm() {
58
58
  }
59
59
  function createNetConnect(orig) {
60
60
  return function (...args) {
61
- const [opts, done] = normalizeArgs(args);
62
- return connect(orig, opts, done);
61
+ const [opt, done] = normalizeArgs(args);
62
+ return connect(orig, opt, done);
63
63
  };
64
64
  }
65
65
  function createTlsConnect(orig) {
66
66
  return function (...args) {
67
- const [opts, done] = normalizeArgs(args);
68
- return connect(orig, opts, done);
67
+ const [opt, done] = normalizeArgs(args);
68
+ return connect(orig, opt, done);
69
69
  };
70
70
  }
71
71
  // Stub network functions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "20.70.0",
4
+ "version": "20.71.0",
5
5
  "dependencies": {
6
6
  "prompts": "^2",
7
7
  "@naturalcycles/js-lib": "^15",
package/readme.md CHANGED
@@ -17,11 +17,6 @@
17
17
  - actionlint
18
18
  - lint-staged
19
19
 
20
- The shared oxlint config ships an opt-in `nc/prefer-assert` rule, off by default. It flags an `if`
21
- whose only statement is `throw new Error(...)` (or `AppError`, `AssertionError`) that reads better
22
- as `_assert(condition, message, data)` from `@naturalcycles/js-lib/error`. Test files are exempt.
23
- Turn it on in your `oxlint.config.ts` with `rules: { 'nc/prefer-assert': 2 }`.
24
-
25
20
  ## How to use
26
21
 
27
22
  Install it: