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' ;
108import { isAbsoluteUrl } from '../ref-utils.js' ;
119import { groupAssertionRules } from './group-assertion-rules.js' ;
@@ -33,18 +31,9 @@ import type {
3331 ResolvedConfig ,
3432 RuleConfig ,
3533 RuleSettings ,
34+ IgnoreConfig ,
3635} from './types.js' ;
3736
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-
4837export class Config {
4938 resolvedConfig : ResolvedConfig ;
5039 configPath ?: string ;
@@ -54,7 +43,7 @@ export class Config {
5443 _alias ?: string ;
5544
5645 plugins : Plugin [ ] ;
57- ignore : Record < string , Record < string , Set < string > > > = { } ;
46+ ignore : IgnoreConfig = { } ;
5847 doNotResolveExamples : boolean ;
5948 rules : Record < SpecVersion , Record < string , RuleConfig > > ;
6049 preprocessors : Record < SpecVersion , Record < string , PreprocessorConfig > > ;
@@ -71,6 +60,7 @@ export class Config {
7160 resolvedRefMap ?: ResolvedRefMap ;
7261 alias ?: string ;
7362 plugins ?: Plugin [ ] ;
63+ ignore ?: IgnoreConfig ;
7464 } = { }
7565 ) {
7666 this . resolvedConfig = resolvedConfig ;
@@ -153,7 +143,7 @@ export class Config {
153143 } ,
154144 } ;
155145
156- this . resolveIgnore ( getIgnoreFilePath ( opts . configPath ) ) ;
146+ this . ignore = opts . ignore ?? { } ;
157147 }
158148
159149 forAlias ( alias ?: string ) {
@@ -171,35 +161,11 @@ export class Config {
171161 resolvedRefMap : this . resolvedRefMap ,
172162 alias,
173163 plugins : this . plugins ,
164+ ignore : this . ignore ,
174165 }
175166 ) ;
176167 }
177168
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-
203169 saveIgnore ( ) {
204170 const dir = this . configPath ? path . dirname ( this . configPath ) : process . cwd ( ) ;
205171 const ignoreFile = path . join ( dir , IGNORE_FILE ) ;
0 commit comments