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,47 @@ 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+ // No configuration file found, using the default one
26+ usingDefault = true ;
27+ configuration . baseConfig = require ( './.eslintrc.js' ) ;
28+ configuration . overrideConfigFile = true ;
2829 }
2930
3031 if ( options ) {
3132 Hoek . merge ( configuration , options , true , false ) ;
3233 }
3334
34- if ( ! configuration . extensions ) {
35- configuration . extensions = [ '.js' , '.cjs' , '.mjs' ] ;
35+ // Only the default configuration should be altered, otherwise the user's configuration should be used as is
36+ if ( usingDefault ) {
37+ if ( ! configuration . extensions ) {
38+ const extensions = [ 'js' , 'cjs' , 'mjs' ] ;
39+
40+ if ( configuration . typescript ) {
41+ extensions . push ( 'ts' ) ;
42+ }
3643
37- if ( configuration . typescript ) {
38- configuration . extensions . push ( '.ts' ) ;
44+ configuration . baseConfig . unshift ( {
45+ files : extensions . map ( ( ext ) => `**/*.${ ext } ` )
46+ } ) ;
3947 }
40- }
4148
42- if ( configuration . typescript ) {
43- delete configuration . typescript ;
49+ if ( configuration . ignores ) {
50+ configuration . baseConfig . unshift ( {
51+ ignores : configuration . ignores
52+ } ) ;
53+ }
4454 }
4555
56+ delete configuration . extensions ;
57+ delete configuration . typescript ;
58+ delete configuration . ignores ;
59+
60+
4661 let results ;
4762 try {
4863 const eslint = new Eslint . ESLint ( configuration ) ;
@@ -66,6 +81,13 @@ exports.lint = async function () {
6681
6782 transformed . errors = result . messages . map ( ( err ) => {
6883
84+ if ( err . messageTemplate === 'all-matched-files-ignored' ) {
85+ return {
86+ severity : 'ERROR' ,
87+ message : err . message
88+ } ;
89+ }
90+
6991 return {
7092 line : err . line ,
7193 severity : err . severity === 1 ? 'WARNING' : 'ERROR' ,
0 commit comments