Skip to content

Commit

Permalink
tools: fix node-core/required-modules eslint rule
Browse files Browse the repository at this point in the history
Make the node-core/required-modules eslint rule smart enough
to recognize that `import '../common/index.mjs'` in ESM files
imports the mandatory 'common' module.

PR-URL: #27545
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
bnoordhuis authored and targos committed May 6, 2019
1 parent de337bb commit 3d37414
Show file tree
Hide file tree
Showing 29 changed files with 6 additions and 35 deletions.
1 change: 0 additions & 1 deletion test/es-module/test-esm-basic-imports.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import assert from 'assert';
import ok from '../fixtures/es-modules/test-esm-ok.mjs';
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-cyclic-dynamic-import.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import('./test-esm-cyclic-dynamic-import.mjs');
1 change: 0 additions & 1 deletion test/es-module/test-esm-double-encoding.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';

// Assert we can import files with `%` in their pathname.
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-encoded-path.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import assert from 'assert';
// ./test-esm-ok.mjs
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-forbidden-globals.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';

// eslint-disable-next-line no-undef
Expand Down
2 changes: 0 additions & 2 deletions test/es-module/test-esm-import-meta.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */

import '../common/index.mjs';
import assert from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-json-cache.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules --experimental-json-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';

import { strictEqual, deepStrictEqual } from 'assert';
Expand Down
2 changes: 0 additions & 2 deletions test/es-module/test-esm-json.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules --experimental-json-modules
/* eslint-disable node-core/required-modules */

import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down
2 changes: 0 additions & 2 deletions test/es-module/test-esm-live-binding.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */

import '../common/index.mjs';
import assert from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-loader-invalid-format.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-format.mjs
/* eslint-disable node-core/required-modules */
import { expectsError, mustCall } from '../common/index.mjs';
import assert from 'assert';

Expand Down
2 changes: 0 additions & 2 deletions test/es-module/test-esm-loader-invalid-url.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs
/* eslint-disable node-core/required-modules */

import { expectsError, mustCall } from '../common/index.mjs';
import assert from 'assert';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/missing-dynamic-instantiate-hook.mjs
/* eslint-disable node-core/required-modules */

import { expectsError } from '../common/index.mjs';

import('test').catch(expectsError({
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-main-lookup.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import assert from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-named-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import { readFile } from 'fs';
import assert from 'assert';
Expand Down
2 changes: 0 additions & 2 deletions test/es-module/test-esm-namespace.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */

import '../common/index.mjs';
import * as fs from 'fs';
import assert from 'assert';
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-process.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import assert from 'assert';
import process from 'process';
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-require-cache.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import { createRequire } from '../common/index.mjs';
import assert from 'assert';
//
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-shared-loader-dep.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-shared-dep.mjs
/* eslint-disable node-core/required-modules */
import { createRequire } from '../common/index.mjs';

import assert from 'assert';
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-shebang.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#! }]) // isn't js
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';

const isJs = true;
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-snapshot.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import '../fixtures/es-modules/esm-snapshot-mutator.js';
import one from '../fixtures/es-modules/esm-snapshot.js';
Expand Down
2 changes: 0 additions & 2 deletions test/es-module/test-esm-throw-undefined.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */

import '../common/index.mjs';
import assert from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-type-flag.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import cjs from '../fixtures/baz.js';
import '../common/index.mjs';
import { message } from '../fixtures/es-modules/message.mjs';
Expand Down
1 change: 0 additions & 1 deletion test/message/async_error_sync_esm.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import four from '../fixtures/async-error.js';

Expand Down
2 changes: 1 addition & 1 deletion test/message/async_error_sync_esm.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Error: test
at two (*fixtures*async-error.js:17:9)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*message*async_error_sync_esm.mjs:8:5)
at async main (*message*async_error_sync_esm.mjs:7:5)
2 changes: 1 addition & 1 deletion test/message/esm_display_syntax_error_import.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Flags: --experimental-modules
/* eslint-disable no-unused-vars, node-core/required-modules */
/* eslint-disable no-unused-vars */
import '../common/index.mjs';
import {
foo,
Expand Down
1 change: 0 additions & 1 deletion test/message/esm_display_syntax_error_import_module.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import '../fixtures/es-module-loaders/syntax-error-import.mjs';
1 change: 0 additions & 1 deletion test/message/esm_display_syntax_error_module.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import '../common/index.mjs';
import '../fixtures/es-module-loaders/syntax-error.mjs';
1 change: 0 additions & 1 deletion test/parallel/test-loaders-unknown-builtin-module.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs
/* eslint-disable node-core/required-modules */
import { expectsError, mustCall } from '../common/index.mjs';
import assert from 'assert';

Expand Down
4 changes: 4 additions & 0 deletions tools/eslint-rules/required-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ module.exports = function(context) {
* @returns {undefined|String} required module name or undefined
*/
function getRequiredModuleName(str) {
if (str === '../common/index.mjs') {
return 'common';
}

const value = path.basename(str);

// Check if value is in required modules array
Expand Down

0 comments on commit 3d37414

Please sign in to comment.