File tree Expand file tree Collapse file tree 3 files changed +6
-7
lines changed Expand file tree Collapse file tree 3 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
17
17
- [ Docs] [ ` no-duplicates ` ] : fix example schema ([ #2684 ] , thanks [ @simmo ] )
18
18
- [ Docs] [ ` group-exports ` ] : fix syntax highlighting ([ #2699 ] , thanks [ @devinrhode2 ] )
19
19
- [ Docs] [ ` extensions ` ] : reference node ESM behavior ([ #2748 ] , thanks [ @xM8WVqaG ] )
20
+ - [ Refactor] [ ` exports-last ` ] : use ` array.prototype.findlastindex ` (thanks [ @ljharb ] )
20
21
21
22
## [ 2.27.5] - 2023-01-16
22
23
Original file line number Diff line number Diff line change 102
102
},
103
103
"dependencies" : {
104
104
"array-includes" : " ^3.1.6" ,
105
+ "array.prototype.findlastindex" : " ^1.2.2" ,
105
106
"array.prototype.flat" : " ^1.3.1" ,
106
107
"array.prototype.flatmap" : " ^1.3.1" ,
107
108
"debug" : " ^3.2.7" ,
Original file line number Diff line number Diff line change
1
+ import findLastIndex from 'array.prototype.findlastindex' ;
2
+
1
3
import docsUrl from '../docsUrl' ;
2
4
3
5
function isNonExportStatement ( { type } ) {
@@ -20,15 +22,10 @@ module.exports = {
20
22
create ( context ) {
21
23
return {
22
24
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 ) ;
29
26
30
27
if ( lastNonExportStatementIndex !== - 1 ) {
31
- body . slice ( 0 , lastNonExportStatementIndex ) . forEach ( function checkNonExport ( node ) {
28
+ body . slice ( 0 , lastNonExportStatementIndex ) . forEach ( ( node ) => {
32
29
if ( ! isNonExportStatement ( node ) ) {
33
30
context . report ( {
34
31
node,
You can’t perform that action at this time.
0 commit comments