Skip to content

chore: migrate to eslint-config-webpack #453

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
Jun 10, 2025
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"anotherhashishere",
"arcanis",
"Builtins",
"camelcase",
"complexm",
"endregion",
"entrypoints",
Expand Down
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

82 changes: 0 additions & 82 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: |
yarn upgrade typescript@^4 --ignore-engines
yarn --frozen-lockfile
if: matrix.node-version == '10.x' || matrix.node-version == '12.x'
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x' || matrix.node-version == '18.x'
- name: Install dependencies
run: yarn --frozen-lockfile
if: matrix.node-version != '10.x'
Expand Down
17 changes: 10 additions & 7 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
"use strict";

module.exports = {
printWidth: 80,
useTabs: true,
tabWidth: 2,
trailingComma: "none",
trailingComma: "all",
arrowParens: "always",
overrides: [
{
files: "*.json",
options: {
parser: "json",
useTabs: false
}
useTabs: false,
},
},
{
files: "*.{cts,mts,ts}",
options: {
parser: "typescript"
}
}
]
parser: "typescript",
},
},
],
};
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ myResolver.resolve(
lookupStartPath,
request,
resolveContext,
(err /*Error*/, filepath /*string*/) => {
(err /* Error */, filepath /* string */) => {
// Do something with the path
}
);
Expand Down Expand Up @@ -151,7 +151,7 @@ enhanced-resolve will try to resolve requests containing `#` as path and as frag

## Tests

```javascript
```sh
yarn test
```

Expand Down
12 changes: 12 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "eslint/config";
import config from "eslint-config-webpack";

export default defineConfig([
{
extends: [config],
rules: {
"n/prefer-global/process": "off",
"n/prefer-node-protocol": "off",
},
},
]);
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use strict";

module.exports = {
moduleFileExtensions: ["js", "mjs", "cjs", "ts"]
prettierPath: require.resolve("prettier-2"),
moduleFileExtensions: ["js", "mjs", "cjs", "ts"],
};
39 changes: 18 additions & 21 deletions lib/AliasFieldPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,38 @@ module.exports = class AliasFieldPlugin {
if (!innerRequest) return callback();
const fieldData = DescriptionFileUtils.getField(
request.descriptionFileData,
this.field
this.field,
);
if (fieldData === null || typeof fieldData !== "object") {
if (resolveContext.log)
if (resolveContext.log) {
resolveContext.log(
"Field '" +
this.field +
"' doesn't contain a valid alias configuration"
`Field '${
this.field
}' doesn't contain a valid alias configuration`,
);
}
return callback();
}
/** @type {JsonPrimitive | undefined} */
const data = Object.prototype.hasOwnProperty.call(
fieldData,
innerRequest
innerRequest,
)
? /** @type {{[Key in string]: JsonPrimitive}} */ (fieldData)[
innerRequest
]
]
: innerRequest.startsWith("./")
? /** @type {{[Key in string]: JsonPrimitive}} */ (fieldData)[
innerRequest.slice(2)
]
: undefined;
? /** @type {{[Key in string]: JsonPrimitive}} */ (fieldData)[
innerRequest.slice(2)
]
: undefined;
if (data === innerRequest) return callback();
if (data === undefined) return callback();
if (data === false) {
/** @type {ResolveRequest} */
const ignoreObj = {
...request,
path: false
path: false,
};
if (typeof resolveContext.yield === "function") {
resolveContext.yield(ignoreObj);
Expand All @@ -82,26 +83,22 @@ module.exports = class AliasFieldPlugin {
...request,
path: /** @type {string} */ (request.descriptionFileRoot),
request: /** @type {string} */ (data),
fullySpecified: false
fullySpecified: false,
};
resolver.doResolve(
target,
obj,
"aliased from description file " +
request.descriptionFilePath +
" with mapping '" +
innerRequest +
"' to '" +
/** @type {string} */ (data) +
"'",
`aliased from description file ${
request.descriptionFilePath
} with mapping '${innerRequest}' to '${/** @type {string} */ data}'`,
resolveContext,
(err, result) => {
if (err) return callback(err);

// Don't allow other aliasing or raw request
if (result === undefined) return callback(null, null);
callback(null, result);
}
},
);
});
}
Expand Down
31 changes: 13 additions & 18 deletions lib/AliasPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = class AliasPlugin {
/** @type {ResolveRequest} */
const ignoreObj = {
...request,
path: false
path: false,
};
if (typeof resolveContext.yield === "function") {
resolveContext.yield(ignoreObj);
Expand All @@ -105,15 +105,15 @@ module.exports = class AliasPlugin {
) {
const match = innerRequest.slice(
prefix.length,
innerRequest.length - suffix.length
innerRequest.length - suffix.length,
);
newRequestStr = item.alias.toString().replace("*", match);
}

if (
matchRequest &&
innerRequest !== alias &&
!innerRequest.startsWith(alias + "/")
!innerRequest.startsWith(`${alias}/`)
) {
/** @type {string} */
const remainingRequest = innerRequest.slice(item.name.length);
Expand All @@ -126,32 +126,28 @@ module.exports = class AliasPlugin {
const obj = {
...request,
request: newRequestStr,
fullySpecified: false
fullySpecified: false,
};
return resolver.doResolve(
target,
obj,
"aliased with mapping '" +
item.name +
"': '" +
alias +
"' to '" +
newRequestStr +
"'",
`aliased with mapping '${item.name}': '${alias}' to '${
newRequestStr
}'`,
resolveContext,
(err, result) => {
if (err) return callback(err);
if (result) return callback(null, result);
return callback();
}
},
);
}
return callback();
};

/**
* @param {null|Error} [err] error
* @param {null|ResolveRequest} [result] result
* @param {(null | Error)=} err error
* @param {(null | ResolveRequest)=} result result
* @returns {void}
*/
const stoppingCallback = (err, result) => {
Expand All @@ -167,16 +163,15 @@ module.exports = class AliasPlugin {
return forEachBail(
item.alias,
resolveWithAlias,
stoppingCallback
stoppingCallback,
);
} else {
return resolveWithAlias(item.alias, stoppingCallback);
}
return resolveWithAlias(item.alias, stoppingCallback);
}

return callback();
},
callback
callback,
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/AppendPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ module.exports = class AppendPlugin {
...request,
path: request.path + this.appending,
relativePath:
request.relativePath && request.relativePath + this.appending
request.relativePath && request.relativePath + this.appending,
};
resolver.doResolve(
target,
obj,
this.appending,
resolveContext,
callback
callback,
);
});
}
Expand Down
Loading