Skip to content

Commit b5c278f

Browse files
authored
Merge branch 'main' into pr/extensions-checkTypeImports
2 parents 991f0ca + 3a5ad34 commit b5c278f

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1717
- [Docs] [`no-duplicates`]: fix example schema ([#2684], thanks [@simmo])
1818
- [Docs] [`group-exports`]: fix syntax highlighting ([#2699], thanks [@devinrhode2])
1919
- [Docs] [`extensions`]: reference node ESM behavior ([#2748], thanks [@xM8WVqaG])
20+
- [Refactor] [`exports-last`]: use `array.prototype.findlastindex` (thanks [@ljharb])
21+
- [Refactor] [`no-anonymous-default-export`]: use `object.fromentries` (thanks [@ljharb])
22+
- [Refactor] [`no-unused-modules`]: use `array.prototype.flatmap` (thanks [@ljharb])
2023

2124
## [2.27.5] - 2023-01-16
2225

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"keywords": [
4343
"eslint",
4444
"eslintplugin",
45+
"eslint-plugin",
4546
"es6",
4647
"jsnext",
4748
"modules",
@@ -101,6 +102,7 @@
101102
},
102103
"dependencies": {
103104
"array-includes": "^3.1.6",
105+
"array.prototype.findlastindex": "^1.2.2",
104106
"array.prototype.flat": "^1.3.1",
105107
"array.prototype.flatmap": "^1.3.1",
106108
"debug": "^3.2.7",
@@ -111,6 +113,7 @@
111113
"is-core-module": "^2.12.1",
112114
"is-glob": "^4.0.3",
113115
"minimatch": "^3.1.2",
116+
"object.fromentries": "^2.0.6",
114117
"object.values": "^1.1.6",
115118
"resolve": "^1.22.3",
116119
"semver": "^6.3.0",

src/rules/exports-last.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import findLastIndex from 'array.prototype.findlastindex';
2+
13
import docsUrl from '../docsUrl';
24

35
function isNonExportStatement({ type }) {
@@ -20,15 +22,10 @@ module.exports = {
2022
create(context) {
2123
return {
2224
Program({ body }) {
23-
const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {
24-
if (isNonExportStatement(item)) {
25-
return index;
26-
}
27-
return acc;
28-
}, -1);
25+
const lastNonExportStatementIndex = findLastIndex(body, isNonExportStatement);
2926

3027
if (lastNonExportStatementIndex !== -1) {
31-
body.slice(0, lastNonExportStatementIndex).forEach(function checkNonExport(node) {
28+
body.slice(0, lastNonExportStatementIndex).forEach((node) => {
3229
if (!isNonExportStatement(node)) {
3330
context.report({
3431
node,

src/rules/no-anonymous-default-export.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* @author Duncan Beevers
44
*/
55

6-
import docsUrl from '../docsUrl';
76
import has from 'has';
7+
import values from 'object.values';
8+
import fromEntries from 'object.fromentries';
9+
10+
import docsUrl from '../docsUrl';
811

912
const defs = {
1013
ArrayExpression: {
@@ -68,12 +71,7 @@ const schemaProperties = Object.keys(defs)
6871
return acc;
6972
}, {});
7073

71-
const defaults = Object.keys(defs)
72-
.map((key) => defs[key])
73-
.reduce((acc, def) => {
74-
acc[def.option] = has(def, 'default') ? def.default : false;
75-
return acc;
76-
}, {});
74+
const defaults = fromEntries(values(defs).map((def) => [def.option, has(def, 'default') ? def.default : false]));
7775

7876
module.exports = {
7977
meta: {

src/rules/no-unused-modules.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
* @author René Fermann
55
*/
66

7-
import Exports, { recursivePatternCapture } from '../ExportMap';
87
import { getFileExtensions } from 'eslint-module-utils/ignore';
98
import resolve from 'eslint-module-utils/resolve';
109
import visit from 'eslint-module-utils/visit';
11-
import docsUrl from '../docsUrl';
1210
import { dirname, join } from 'path';
1311
import readPkgUp from 'eslint-module-utils/readPkgUp';
1412
import values from 'object.values';
1513
import includes from 'array-includes';
14+
import flatMap from 'array.prototype.flatmap';
15+
16+
import Exports, { recursivePatternCapture } from '../ExportMap';
17+
import docsUrl from '../docsUrl';
1618

1719
let FileEnumerator;
1820
let listFilesToProcess;
@@ -40,12 +42,7 @@ try {
4042
const { listFilesToProcess: originalListFilesToProcess } = require('eslint/lib/util/glob-util');
4143

4244
listFilesToProcess = function (src, extensions) {
43-
const patterns = src.reduce(
44-
(carry, pattern) => carry.concat(
45-
extensions.map((extension) => (/\*\*|\*\./).test(pattern) ? pattern : `${pattern}/**/*${extension}`),
46-
),
47-
src,
48-
);
45+
const patterns = src.concat(flatMap(src, (pattern) => extensions.map((extension) => (/\*\*|\*\./).test(pattern) ? pattern : `${pattern}/**/*${extension}`)));
4946

5047
return originalListFilesToProcess(patterns);
5148
};
@@ -171,18 +168,17 @@ const isNodeModule = (path) => (/\/(node_modules)\//).test(path);
171168
const resolveFiles = (src, ignoreExports, context) => {
172169
const extensions = Array.from(getFileExtensions(context.settings));
173170

174-
const srcFiles = new Set();
175171
const srcFileList = listFilesToProcess(src, extensions);
176172

177173
// prepare list of ignored files
178-
const ignoredFilesList = listFilesToProcess(ignoreExports, extensions);
174+
const ignoredFilesList = listFilesToProcess(ignoreExports, extensions);
179175
ignoredFilesList.forEach(({ filename }) => ignoredFiles.add(filename));
180176

181177
// prepare list of source files, don't consider files from node_modules
182-
srcFileList.filter(({ filename }) => !isNodeModule(filename)).forEach(({ filename }) => {
183-
srcFiles.add(filename);
184-
});
185-
return srcFiles;
178+
179+
return new Set(
180+
srcFileList.filter(({ filename }) => !isNodeModule(filename)).map(({ filename }) => filename),
181+
);
186182
};
187183

188184
/**

0 commit comments

Comments
 (0)