11import * as fs from 'node:fs' ;
22import * as path from 'node:path' ;
3- import { parseYaml , stringifyYaml } from '../js-yaml/index.js' ;
3+ import { stringifyYaml } from '../js-yaml/index.js' ;
44import { slash } from '../utils/slash.js' ;
5- import { doesYamlFileExist } from '../utils/does-yaml-file-exist.js' ;
65import { isPlainObject } from '../utils/is-plain-object.js' ;
76import { specVersions } from '../detect-spec.js' ;
8- import { isBrowser } from '../env.js' ;
97import { getResolveConfig } from './get-resolve-config.js' ;
10- import { isAbsoluteUrl } from '../ref-utils.js' ;
8+ import { isAbsoluteUrl , resolvePath } from '../ref-utils.js' ;
119import { groupAssertionRules } from './group-assertion-rules.js' ;
1210import { IGNORE_BANNER , IGNORE_FILE } from './constants.js' ;
1311
@@ -33,18 +31,10 @@ import type {
3331 ResolvedConfig ,
3432 RuleConfig ,
3533 RuleSettings ,
34+ IgnoreFile ,
35+ ResolvedIgnore ,
3636} from './types.js' ;
3737
38- function getIgnoreFilePath ( configPath ?: string ) : string | undefined {
39- if ( configPath ) {
40- return doesYamlFileExist ( configPath )
41- ? path . join ( path . dirname ( configPath ) , IGNORE_FILE )
42- : path . join ( configPath , IGNORE_FILE ) ;
43- } else {
44- return isBrowser ? undefined : path . join ( process . cwd ( ) , IGNORE_FILE ) ;
45- }
46- }
47-
4838export class Config {
4939 resolvedConfig : ResolvedConfig ;
5040 configPath ?: string ;
@@ -54,7 +44,7 @@ export class Config {
5444 _alias ?: string ;
5545
5646 plugins : Plugin [ ] ;
57- ignore : Record < string , Record < string , Set < string > > > = { } ;
47+ ignore : ResolvedIgnore = { } ;
5848 doNotResolveExamples : boolean ;
5949 rules : Record < SpecVersion , Record < string , RuleConfig > > ;
6050 preprocessors : Record < SpecVersion , Record < string , PreprocessorConfig > > ;
@@ -71,6 +61,8 @@ export class Config {
7161 resolvedRefMap ?: ResolvedRefMap ;
7262 alias ?: string ;
7363 plugins ?: Plugin [ ] ;
64+ ignoreFile ?: IgnoreFile ;
65+ ignore ?: ResolvedIgnore ;
7466 } = { }
7567 ) {
7668 this . resolvedConfig = resolvedConfig ;
@@ -153,7 +145,25 @@ export class Config {
153145 } ,
154146 } ;
155147
156- this . resolveIgnore ( getIgnoreFilePath ( opts . configPath ) ) ;
148+ this . ignore = opts . ignore ?? ( opts . ignoreFile ? this . resolveIgnore ( opts . ignoreFile ) : { } ) ;
149+ }
150+
151+ private resolveIgnore ( { content, dir } : IgnoreFile ) : ResolvedIgnore {
152+ const ignore : ResolvedIgnore = Object . create ( null ) ;
153+
154+ for ( const fileName of Object . keys ( content ) ) {
155+ const fileIgnore = content [ fileName ] ;
156+
157+ const resolvedFileName = isAbsoluteUrl ( fileName ) ? fileName : resolvePath ( dir , fileName ) ;
158+
159+ ignore [ resolvedFileName ] = Object . create ( null ) ;
160+
161+ for ( const ruleId of Object . keys ( fileIgnore ) ) {
162+ ignore [ resolvedFileName ] [ ruleId ] = new Set ( fileIgnore [ ruleId ] ) ;
163+ }
164+ }
165+
166+ return ignore ;
157167 }
158168
159169 forAlias ( alias ?: string ) {
@@ -171,35 +181,11 @@ export class Config {
171181 resolvedRefMap : this . resolvedRefMap ,
172182 alias,
173183 plugins : this . plugins ,
184+ ignore : this . ignore ,
174185 }
175186 ) ;
176187 }
177188
178- resolveIgnore ( ignoreFile ?: string ) {
179- if ( ! ignoreFile || ! doesYamlFileExist ( ignoreFile ) ) return ;
180-
181- this . ignore =
182- ( parseYaml ( fs . readFileSync ( ignoreFile , 'utf-8' ) ) as Record <
183- string ,
184- Record < string , Set < string > >
185- > ) || { } ;
186-
187- // resolve ignore paths
188- for ( const fileName of Object . keys ( this . ignore ) ) {
189- this . ignore [
190- isAbsoluteUrl ( fileName ) ? fileName : path . resolve ( path . dirname ( ignoreFile ) , fileName )
191- ] = this . ignore [ fileName ] ;
192-
193- for ( const ruleId of Object . keys ( this . ignore [ fileName ] ) ) {
194- this . ignore [ fileName ] [ ruleId ] = new Set ( this . ignore [ fileName ] [ ruleId ] ) ;
195- }
196-
197- if ( ! isAbsoluteUrl ( fileName ) ) {
198- delete this . ignore [ fileName ] ;
199- }
200- }
201- }
202-
203189 saveIgnore ( ) {
204190 const dir = this . configPath ? path . dirname ( this . configPath ) : process . cwd ( ) ;
205191 const ignoreFile = path . join ( dir , IGNORE_FILE ) ;
0 commit comments