11'use strict' ;
22
33const Fs = require ( 'fs' ) ;
4- const Path = require ( 'path' ) ;
54
65const Eslint = require ( 'eslint' ) ;
76const Hoek = require ( '@hapi/hoek' ) ;
@@ -18,31 +17,50 @@ exports.lint = async function () {
1817
1918 const options = process . argv [ 2 ] ? JSON . parse ( process . argv [ 2 ] ) : undefined ;
2019
21- if ( ! Fs . existsSync ( '.eslintrc.js' ) &&
22- ! Fs . existsSync ( '.eslintrc.cjs' ) && // Needed for projects with "type": "module"
23- ! Fs . existsSync ( '.eslintrc.yaml' ) &&
24- ! Fs . existsSync ( '.eslintrc.yml' ) &&
25- ! Fs . existsSync ( '.eslintrc.json' ) &&
26- ! Fs . existsSync ( '.eslintrc' ) ) {
27- configuration . overrideConfigFile = Path . join ( __dirname , '.eslintrc.js' ) ;
20+ let usingDefault = false ;
21+
22+ if ( ! Fs . existsSync ( 'eslint.config.js' ) &&
23+ ! Fs . existsSync ( 'eslint.config.cjs' ) &&
24+ ! Fs . existsSync ( 'eslint.config.mjs' ) &&
25+ ! Fs . existsSync ( 'eslint.config.ts' ) &&
26+ ! Fs . existsSync ( 'eslint.config.mts' ) &&
27+ ! Fs . existsSync ( 'eslint.config.cts' ) ) {
28+ // No configuration file found, using the default one
29+ usingDefault = true ;
30+ configuration . baseConfig = require ( './.eslintrc.js' ) ;
31+ configuration . overrideConfigFile = true ;
2832 }
2933
3034 if ( options ) {
3135 Hoek . merge ( configuration , options , true , false ) ;
3236 }
3337
34- if ( ! configuration . extensions ) {
35- configuration . extensions = [ '.js' , '.cjs' , '.mjs' ] ;
38+ // Only the default configuration should be altered, otherwise the user's configuration should be used as is
39+ if ( usingDefault ) {
40+ if ( ! configuration . extensions ) {
41+ const extensions = [ 'js' , 'cjs' , 'mjs' ] ;
3642
37- if ( configuration . typescript ) {
38- configuration . extensions . push ( '.ts' ) ;
43+ if ( configuration . typescript ) {
44+ extensions . push ( 'ts' ) ;
45+ }
46+
47+ configuration . baseConfig . unshift ( {
48+ files : extensions . map ( ( ext ) => `**/*.${ ext } ` )
49+ } ) ;
3950 }
40- }
4151
42- if ( configuration . typescript ) {
43- delete configuration . typescript ;
52+ if ( configuration . ignores ) {
53+ configuration . baseConfig . unshift ( {
54+ ignores : configuration . ignores
55+ } ) ;
56+ }
4457 }
4558
59+ delete configuration . extensions ;
60+ delete configuration . typescript ;
61+ delete configuration . ignores ;
62+
63+
4664 let results ;
4765 try {
4866 const eslint = new Eslint . ESLint ( configuration ) ;
@@ -66,6 +84,13 @@ exports.lint = async function () {
6684
6785 transformed . errors = result . messages . map ( ( err ) => {
6886
87+ if ( err . messageTemplate === 'all-matched-files-ignored' ) {
88+ return {
89+ severity : 'ERROR' ,
90+ message : err . message
91+ } ;
92+ }
93+
6994 return {
7095 line : err . line ,
7196 severity : err . severity === 1 ? 'WARNING' : 'ERROR' ,
0 commit comments