Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v6.x backport) src: use option parser for expose_internals #14483

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test/tmp*/
tools/eslint
node_modules
benchmark/tmp/
doc/**/*.js
4 changes: 3 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
root: true

plugins:
- markdown

env:
node: true
es6: true
Expand Down Expand Up @@ -162,7 +165,6 @@ rules:
# Custom rules in tools/eslint-rules
align-multiline-assignment: 2
assert-throws-arguments: [2, { requireTwo: true }]
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]

# Global scoped method and vars
globals:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,13 @@ bench-idle:

jslint:
@echo "Running JS linter..."
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules \
benchmark lib test tools
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules --ext=.js,.md \
benchmark doc lib test tools

jslint-ci:
@echo "Running JS linter..."
$(NODE) tools/jslint.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
benchmark lib test tools
benchmark doc lib test tools

CPPLINT_EXCLUDE ?=
CPPLINT_EXCLUDE += src/node_root_certs.h
Expand Down
39 changes: 22 additions & 17 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,43 @@ constructor iterates through the configuration object property values and runs
the test function with each of the combined arguments in spawned processes. For
example, buffers/buffer-read.js has the following configuration:

<!-- eslint-disable strict, no-undef, no-unused-vars -->
```js
var bench = common.createBenchmark(main, {
noAssert: [false, true],
buffer: ['fast', 'slow'],
type: ['UInt8', 'UInt16LE', 'UInt16BE',
'UInt32LE', 'UInt32BE',
'Int8', 'Int16LE', 'Int16BE',
'Int32LE', 'Int32BE',
'FloatLE', 'FloatBE',
'DoubleLE', 'DoubleBE'],
millions: [1]
'UInt32LE', 'UInt32BE',
'Int8', 'Int16LE', 'Int16BE',
'Int32LE', 'Int32BE',
'FloatLE', 'FloatBE',
'DoubleLE', 'DoubleBE'],
millions: [1]
});
```
The runner takes one item from each of the property array value to build a list
of arguments to run the main function. The main function will receive the conf
object as follows:

- first run:

<!-- eslint-skip -->
```js
{ noAssert: false,
buffer: 'fast',
type: 'UInt8',
millions: 1
}
{ noAssert: false,
buffer: 'fast',
type: 'UInt8',
millions: 1
}
```
- second run:

<!-- eslint-skip -->
```js
{
noAssert: false,
buffer: 'fast',
type: 'UInt16LE',
millions: 1
}
{ noAssert: false,
buffer: 'fast',
type: 'UInt16LE',
millions: 1
}
```
...

Expand Down Expand Up @@ -122,6 +126,7 @@ buffers/buffer-slice.js.

### The code snippet

<!-- eslint-disable strict, no-undef, no-unused-vars -->
```js
var common = require('../common.js'); // Load the test runner

Expand Down
12 changes: 12 additions & 0 deletions doc/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Docs-specific linter rules

rules:
# ease some restrictions in doc examples
no-restricted-properties: 0
no-undef: 0
no-unused-vars: 0
strict: 0

# add new ECMAScript features gradually
no-var: 2
prefer-const: 2
35 changes: 18 additions & 17 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ are evaluated also:
const assert = require('assert');

const obj1 = {
a : {
b : 1
a: {
b: 1
}
};
const obj2 = {
a : {
b : 2
a: {
b: 2
}
};
const obj3 = {
a : {
b : 1
a: {
b: 1
}
};
const obj4 = Object.create(obj1);
Expand Down Expand Up @@ -93,10 +93,10 @@ Second, object comparisons include a strict equality check of their prototypes.
```js
const assert = require('assert');

assert.deepEqual({a:1}, {a:'1'});
assert.deepEqual({ a: 1 }, { a: '1' });
// OK, because 1 == '1'

assert.deepStrictEqual({a:1}, {a:'1'});
assert.deepStrictEqual({ a: 1 }, { a: '1' });
// AssertionError: { a: 1 } deepStrictEqual { a: '1' }
// because 1 !== '1' using strict equality
```
Expand Down Expand Up @@ -251,18 +251,18 @@ Tests for any deep inequality. Opposite of [`assert.deepEqual()`][].
const assert = require('assert');

const obj1 = {
a : {
b : 1
a: {
b: 1
}
};
const obj2 = {
a : {
b : 2
a: {
b: 2
}
};
const obj3 = {
a : {
b : 1
a: {
b: 1
}
};
const obj4 = Object.create(obj1);
Expand Down Expand Up @@ -297,10 +297,10 @@ Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][].
```js
const assert = require('assert');

assert.notDeepEqual({a:1}, {a:'1'});
assert.notDeepEqual({a: 1}, {a: '1'});
// AssertionError: { a: 1 } notDeepEqual { a: '1' }

assert.notDeepStrictEqual({a:1}, {a:'1'});
assert.notDeepStrictEqual({a: 1}, {a: '1'});
// OK
```

Expand Down Expand Up @@ -466,7 +466,7 @@ assert.throws(
throw new Error('Wrong value');
},
function(err) {
if ( (err instanceof Error) && /value/.test(err) ) {
if ((err instanceof Error) && /value/.test(err)) {
return true;
}
},
Expand All @@ -478,6 +478,7 @@ Note that `error` can not be a string. If a string is provided as the second
argument, then `error` is assumed to be omitted and the string will be used for
`message` instead. This can lead to easy-to-miss mistakes:

<!-- eslint-disable assert-throws-arguments -->
```js
// THIS IS A MISTAKE! DO NOT DO THIS!
assert.throws(myFunction, 'missing foo', 'did not throw with expected message');
Expand Down
16 changes: 8 additions & 8 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ Example: Copy an ASCII string into a `Buffer`, one byte at a time
const str = 'Node.js';
const buf = Buffer.allocUnsafe(str.length);

for (let i = 0; i < str.length ; i++) {
for (let i = 0; i < str.length; i++) {
buf[i] = str.charCodeAt(i);
}

Expand Down Expand Up @@ -994,7 +994,7 @@ byte 16 through byte 19 into `buf2`, starting at the 8th byte in `buf2`
const buf1 = Buffer.allocUnsafe(26);
const buf2 = Buffer.allocUnsafe(26).fill('!');

for (let i = 0 ; i < 26 ; i++) {
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'
buf1[i] = i + 97;
}
Expand All @@ -1011,7 +1011,7 @@ overlapping region within the same `Buffer`
```js
const buf = Buffer.allocUnsafe(26);

for (let i = 0 ; i < 26 ; i++) {
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'
buf[i] = i + 97;
}
Expand Down Expand Up @@ -1781,7 +1781,7 @@ one byte from the original `Buffer`
```js
const buf1 = Buffer.allocUnsafe(26);

for (let i = 0 ; i < 26 ; i++) {
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'
buf1[i] = i + 97;
}
Expand Down Expand Up @@ -1930,7 +1930,7 @@ Examples:
```js
const buf1 = Buffer.allocUnsafe(26);

for (let i = 0 ; i < 26 ; i++) {
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'
buf1[i] = i + 97;
}
Expand Down Expand Up @@ -1974,9 +1974,9 @@ const json = JSON.stringify(buf);
console.log(json);

const copy = JSON.parse(json, (key, value) => {
return value && value.type === 'Buffer'
? Buffer.from(value.data)
: value;
return value && value.type === 'Buffer' ?
Buffer.from(value.data) :
value;
});

// Prints: <Buffer 01 02 03 04 05>
Expand Down
22 changes: 14 additions & 8 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ bat.stderr.on('data', (data) => {
bat.on('exit', (code) => {
console.log(`Child exited with code ${code}`);
});
```

```js
// OR...
const exec = require('child_process').exec;
exec('my.bat', (err, stdout, stderr) => {
Expand Down Expand Up @@ -183,14 +185,14 @@ The `options` argument may be passed as the second argument to customize how
the process is spawned. The default options are:

```js
{
const defaults = {
encoding: 'utf8',
timeout: 0,
maxBuffer: 200*1024,
maxBuffer: 200 * 1024,
killSignal: 'SIGTERM',
cwd: null,
env: null
}
};
```

If `timeout` is greater than `0`, the parent will send the signal
Expand Down Expand Up @@ -335,10 +337,10 @@ trigger arbitrary command execution.**
A third argument may be used to specify additional options, with these defaults:

```js
{
const defaults = {
cwd: undefined,
env: process.env
}
};
```

Use `cwd` to specify the working directory from which the process is spawned.
Expand Down Expand Up @@ -866,13 +868,17 @@ as in this example:
'use strict';
const spawn = require('child_process').spawn;

const child = spawn('sh', ['-c',
`node -e "setInterval(() => {
const child = spawn(
'sh',
[
'-c',
`node -e "setInterval(() => {
console.log(process.pid, 'is alive')
}, 500);"`
], {
stdio: ['inherit', 'inherit', 'inherit']
});
}
);

setTimeout(() => {
child.kill(); // does not terminate the node process in the shell
Expand Down
13 changes: 8 additions & 5 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,14 @@ When any of the workers die the cluster module will emit the `'exit'` event.
This can be used to restart the worker by calling `.fork()` again.

```js
cluster.on('exit', (worker, code, signal) => {
console.log('worker %d died (%s). restarting...',
worker.process.pid, signal || code);
cluster.fork();
});
cluster.on(
'exit',
(worker, code, signal) => {
console.log('worker %d died (%s). restarting...',
worker.process.pid, signal || code);
cluster.fork();
}
);
```

See [child_process event: 'exit'][].
Expand Down
9 changes: 5 additions & 4 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ or `console.Console`:

```js
const Console = require('console').Console;
```

```js
const Console = console.Console;
```

Expand Down Expand Up @@ -127,7 +130,7 @@ the default behavior of `console` in Node.js.
// new impl for assert without monkey-patching.
const myConsole = Object.create(console, {
assert: {
value: function assert(assertion, message, ...args) {
value(assertion, message, ...args) {
try {
console.assert(assertion, message, ...args);
} catch (err) {
Expand Down Expand Up @@ -250,9 +253,7 @@ prints the result to `stdout`:

```js
console.time('100-elements');
for (let i = 0; i < 100; i++) {
;
}
for (let i = 0; i < 100; i++) ;
console.timeEnd('100-elements');
// prints 100-elements: 225.438ms
```
Expand Down
Loading