Skip to content

refactor(eslint): make global-require to off #2137

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

Merged
merged 2 commits into from
Jul 22, 2019
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"no-underscore-dangle": "off",
"prefer-destructuring": ["error", { "object": false, "array": false }],
"prefer-rest-params": "off",
"strict": ["error", "safe"]
"strict": ["error", "safe"],
"global-require": "off"
}
}
1 change: 0 additions & 1 deletion bin/options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

/* eslint-disable
global-require,
multiline-ternary,
space-before-function-paren
*/
Expand Down
1 change: 0 additions & 1 deletion client-src/default/utils/reloadApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function reloadApp(
}
if (hot) {
log.info('[WDS] App hot update...');
// eslint-disable-next-line global-require
const hotEmitter = require('webpack/hot/emitter');
hotEmitter.emit('webpackHotUpdate', currentHash);
if (typeof self !== 'undefined' && self.window) {
Expand Down
2 changes: 1 addition & 1 deletion client-src/live/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

/* eslint import/no-extraneous-dependencies: off, global-require: off */
/* eslint import/no-extraneous-dependencies: off */

const $ = require('jquery');
const stripAnsi = require('strip-ansi');
Expand Down
1 change: 0 additions & 1 deletion examples/general/proxy-hot-reload/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

/* eslint global-require: off */
const fs = require('fs');
// our setup function adds behind-the-scenes bits to the config that all of our
// examples need
Expand Down
1 change: 0 additions & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ class Server {
// The relevant issues are:
// https://github.com/spdy-http2/node-spdy/issues/350
// https://github.com/webpack/webpack-dev-server/issues/1592
// eslint-disable-next-line global-require
this.listeningApp = require('spdy').createServer(
this.options.https,
this.app
Expand Down
1 change: 0 additions & 1 deletion lib/servers/SockJSServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const BaseServer = require('./BaseServer');
// sockjs will remove Origin header, however Origin header is required for checking host.
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
{
// eslint-disable-next-line global-require
const SockjsSession = require('sockjs/lib/transport').Session;
const decorateConnection = SockjsSession.prototype.decorateConnection;
SockjsSession.prototype.decorateConnection = function(req) {
Expand Down
4 changes: 1 addition & 3 deletions lib/utils/getSocketClientPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ function getSocketClientPath(options) {
case 'string':
// could be 'sockjs', 'ws', or a path that should be required
if (options.clientMode === 'sockjs') {
// eslint-disable-next-line global-require
ClientImplementation = require('../../client/clients/SockJSClient');
} else if (options.clientMode === 'ws') {
// eslint-disable-next-line global-require
ClientImplementation = require('../../client/clients/WebsocketClient');
} else {
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
// eslint-disable-next-line import/no-dynamic-require
ClientImplementation = require(options.clientMode);
} catch (e) {
clientImplFound = false;
Expand Down
4 changes: 1 addition & 3 deletions lib/utils/getSocketServerImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ function getSocketServerImplementation(options) {
case 'string':
// could be 'sockjs', in the future 'ws', or a path that should be required
if (options.serverMode === 'sockjs') {
// eslint-disable-next-line global-require
ServerImplementation = require('../servers/SockJSServer');
} else if (options.serverMode === 'ws') {
// eslint-disable-next-line global-require
ServerImplementation = require('../servers/WebsocketServer');
} else {
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
// eslint-disable-next-line import/no-dynamic-require
ServerImplementation = require(options.serverMode);
} catch (e) {
serverImplFound = false;
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/getVersions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

/* eslint-disable global-require */

function getVersions() {
return (
`webpack-dev-server ${require('../../package.json').version}\n` +
Expand Down
1 change: 0 additions & 1 deletion lib/utils/runBonjour.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

function runBonjour(options) {
// eslint-disable-next-line global-require
const bonjour = require('bonjour')();

bonjour.publish({
Expand Down
1 change: 0 additions & 1 deletion test/client/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

/* eslint-disable
global-require,
no-undefined
*/
/* global self */
Expand Down
4 changes: 0 additions & 4 deletions test/client/socket-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ describe('socket', () => {

it('should default to SockJSClient when no __webpack_dev_server_client__ set', () => {
jest.mock('../../client/clients/SockJSClient');
// eslint-disable-next-line global-require
const socket = require('../../client/socket');
// eslint-disable-next-line global-require
const SockJSClient = require('../../client/clients/SockJSClient');

const mockHandler = jest.fn();
Expand Down Expand Up @@ -38,9 +36,7 @@ describe('socket', () => {

it('should use __webpack_dev_server_client__ when set', () => {
jest.mock('../../client/clients/SockJSClient');
// eslint-disable-next-line global-require
const socket = require('../../client/socket');
// eslint-disable-next-line global-require
global.__webpack_dev_server_client__ = require('../../client/clients/SockJSClient');

const mockHandler = jest.fn();
Expand Down
1 change: 0 additions & 1 deletion test/client/utils/createSocketUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('createSocketUrl', () => {
() => () => url
);

// eslint-disable-next-line global-require
const createSocketUrl = require('../../../client-src/default/utils/createSocketUrl');

test(`should return the url when __resourceQuery is ${url}`, () => {
Expand Down
2 changes: 0 additions & 2 deletions test/client/utils/log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe('log', () => {

beforeEach(() => {
jest.mock('loglevel');
// eslint-disable-next-line global-require
logMock = require('loglevel');
logMock.getLogger.mockImplementation(() => {
return {
Expand All @@ -17,7 +16,6 @@ describe('log', () => {
};
});

// eslint-disable-next-line global-require
setLogLevel = require('../../../client-src/default/utils/log').setLogLevel;
});

Expand Down
3 changes: 0 additions & 3 deletions test/client/utils/reloadApp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('reloadApp', () => {

jest.mock('loglevel');

// eslint-disable-next-line global-require
log = require('loglevel');
log.getLogger.mockImplementation(() => {
return {
Expand All @@ -24,7 +23,6 @@ describe('reloadApp', () => {
};
});

// eslint-disable-next-line global-require
reloadApp = require('../../../client-src/default/utils/reloadApp');
});

Expand All @@ -47,7 +45,6 @@ describe('reloadApp', () => {

test('should run hot', () => {
jest.mock('webpack/hot/emitter');
// eslint-disable-next-line global-require
const emitter = require('webpack/hot/emitter');
emitter.emit = jest.fn();

Expand Down
1 change: 0 additions & 1 deletion test/e2e/Progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('client progress', () => {
processStderrMock = jest
.spyOn(process.stderr, 'write')
.mockImplementation();
// eslint-disable-next-line global-require
testServer = require('../helpers/test-server');

fs.writeFileSync(
Expand Down
1 change: 0 additions & 1 deletion test/server/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ describe('Server', () => {
it('should be present', () => {
expect(process.env.WEBPACK_DEV_SERVER).toBeUndefined();

// eslint-disable-next-line global-require
require('../../lib/Server');

expect(process.env.WEBPACK_DEV_SERVER).toBe(true);
Expand Down
3 changes: 0 additions & 3 deletions test/server/clientMode-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('clientMode option', () => {
describe('is passed to getSocketClientPath correctly', () => {
beforeEach(() => {
jest.mock('../../lib/utils/getSocketClientPath');
// eslint-disable-next-line global-require
getSocketClientPath = require('../../lib/utils/getSocketClientPath');
});

Expand All @@ -42,7 +41,6 @@ describe('clientMode option', () => {

clientModes.forEach((data) => {
it(data.title, (done) => {
// eslint-disable-next-line global-require
mockedTestServer = require('../helpers/test-server');
mockedTestServer.start(
config,
Expand All @@ -67,7 +65,6 @@ describe('clientMode option', () => {
describe('passed to server', () => {
beforeAll(() => {
jest.unmock('../../lib/utils/getSocketClientPath');
// eslint-disable-next-line global-require
testServer = require('../helpers/test-server');
});

Expand Down
2 changes: 0 additions & 2 deletions test/server/http2-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ describe('http2 option', () => {
semver.gte(process.version, '8.8.0') &&
semver.lt(process.version, '10.0.0')
) {
/* eslint-disable global-require */
const http2 = require('http2');
/* eslint-enable global-require */
describe('http2 works with https', () => {
beforeAll((done) => {
server = testServer.start(
Expand Down
5 changes: 0 additions & 5 deletions test/server/serverMode-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('serverMode option', () => {
describe('is passed to getSocketServerImplementation correctly', () => {
beforeEach(() => {
jest.mock('../../lib/utils/getSocketServerImplementation');
// eslint-disable-next-line global-require
getSocketServerImplementation = require('../../lib/utils/getSocketServerImplementation');
getSocketServerImplementation.mockImplementation(() => {
return class MockServer {
Expand All @@ -76,7 +75,6 @@ describe('serverMode option', () => {

serverModes.forEach((data) => {
it(data.title, (done) => {
// eslint-disable-next-line global-require
mockedTestServer = require('../helpers/test-server');
mockedTestServer.start(
config,
Expand All @@ -102,7 +100,6 @@ describe('serverMode option', () => {
describe('passed to server', () => {
beforeAll(() => {
jest.unmock('../../lib/utils/getSocketServerImplementation');
// eslint-disable-next-line global-require
testServer = require('../helpers/test-server');
});

Expand Down Expand Up @@ -410,9 +407,7 @@ describe('serverMode option', () => {
let MockSockJSServer;
beforeEach((done) => {
jest.mock('../../lib/servers/SockJSServer');
// eslint-disable-next-line global-require
mockedTestServer = require('../helpers/test-server');
// eslint-disable-next-line global-require
MockSockJSServer = require('../../lib/servers/SockJSServer');

server = mockedTestServer.start(
Expand Down
4 changes: 0 additions & 4 deletions test/server/utils/updateCompiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('updateCompiler', () => {
describe('simple config, inline', () => {
let compiler;
beforeAll(() => {
// eslint-disable-next-line global-require
const webpackConfig = require('../../fixtures/simple-config/webpack.config');
compiler = webpack(webpackConfig);
});
Expand Down Expand Up @@ -44,7 +43,6 @@ describe('updateCompiler', () => {
describe('simple config, hot and inline', () => {
let compiler;
beforeAll(() => {
// eslint-disable-next-line global-require
const webpackConfig = require('../../fixtures/simple-config/webpack.config');
compiler = webpack(webpackConfig);
});
Expand Down Expand Up @@ -81,7 +79,6 @@ describe('updateCompiler', () => {
describe('simple config with HMR already, hot and inline', () => {
let compiler;
beforeAll(() => {
// eslint-disable-next-line global-require
const webpackConfig = require('../../fixtures/simple-config/webpack.config');
webpackConfig.plugins = [new webpack.HotModuleReplacementPlugin()];
compiler = webpack(webpackConfig);
Expand Down Expand Up @@ -119,7 +116,6 @@ describe('updateCompiler', () => {
describe('multi compiler config, hot and inline', () => {
let multiCompiler;
beforeAll(() => {
// eslint-disable-next-line global-require
const webpackConfig = require('../../fixtures/multi-compiler-2-config/webpack.config');
webpackConfig[1].plugins = [new webpack.HotModuleReplacementPlugin()];
multiCompiler = webpack(webpackConfig);
Expand Down