File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
test/fixtures/context_properties Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,9 @@ export interface InternalContext {
8989 messages : Record < string , string > | null ;
9090}
9191
92+ // Cached current working directory.
93+ let cachedCwd : string | null = null ;
94+
9295/**
9396 * Context class.
9497 *
@@ -132,6 +135,12 @@ export class Context {
132135 return getInternal ( this , 'access `context.physicalFilename`' ) . filePath ;
133136 }
134137
138+ // Getter for current working directory.
139+ get cwd ( ) {
140+ getInternal ( this , 'access `context.cwd`' ) ;
141+ return cachedCwd ??= process . cwd ( ) ;
142+ }
143+
135144 // Getter for options for file being linted.
136145 get options ( ) {
137146 return getInternal ( this , 'access `context.options`' ) . options ;
Original file line number Diff line number Diff line change @@ -35,6 +35,14 @@ const rule: Rule = {
3535 node : SPAN ,
3636 } ) ;
3737
38+ if ( context . cwd . length === 0 ) {
39+ context . report ( { message : 'cwd.length === 0' , node : SPAN } ) ;
40+ }
41+
42+ if ( context . cwd !== process . cwd ( ) ) {
43+ context . report ( { message : 'cwd !== process.cwd()' , node : SPAN } ) ;
44+ }
45+
3846 if ( this !== rule ) context . report ( { message : 'this !== rule' , node : SPAN } ) ;
3947
4048 return {
You can’t perform that action at this time.
0 commit comments