@@ -20,7 +20,6 @@ const { filterAuthoredDocsPageFiles } = require('../../tools/lib/docs-page-scope
2020const lintCopy = require ( '../../tools/scripts/lint-copy' ) ;
2121const lintStructure = require ( '../../tools/scripts/lint-structure' ) ;
2222const lintPatterns = require ( '../../tools/scripts/lint-patterns' ) ;
23- const patternObserver = require ( '../../tools/scripts/pattern-observer' ) ;
2423
2524const REPO_ROOT = path . resolve ( __dirname , '..' , '..' ) ;
2625const FIXTURE_ROOT = path . join ( REPO_ROOT , 'tests' , 'copy-lint-fixtures' ) ;
@@ -80,19 +79,49 @@ function analyzeStructure(content, filePath) {
8079 ] ;
8180}
8281
83- function analyzeFile ( filePath , options = { } ) {
84- const { includePatternChecks = false } = options ;
85- const content = fs . readFileSync ( filePath , 'utf8' ) ;
86- const findings = [
87- ... lintCopy . checkBannedWords ( content , filePath ) ,
88- ...lintCopy . checkBannedPhrases ( content , filePath ) ,
89- ...lintCopy . checkTier2Patterns ( content , filePath ) ,
90- ...analyzeStructure ( content , filePath )
82+ function buildCopyFindings ( content , filePath ) {
83+ const phraseFindings = lintCopy . checkBannedPhrases ( content , filePath ) ;
84+ const phraseHitLines = new Set ( phraseFindings . map ( ( finding ) => finding . line ) ) ;
85+
86+ return [
87+ ...phraseFindings ,
88+ ...lintCopy . checkBannedWords ( content , filePath , { suppressedLines : phraseHitLines } ) ,
89+ ...lintCopy . checkTier2Patterns ( content , filePath )
9190 ] ;
91+ }
9292
93- if ( includePatternChecks ) {
94- findings . push ( ...lintPatterns . checkFile ( filePath ) ) ;
95- }
93+ function mergeFindings ( ...groups ) {
94+ const merged = [ ] ;
95+ const seen = new Set ( ) ;
96+
97+ groups . flat ( ) . forEach ( ( finding ) => {
98+ const key = [
99+ finding . file || '' ,
100+ finding . line || 0 ,
101+ finding . tier || 0 ,
102+ finding . id || '' ,
103+ finding . match || ''
104+ ] . join ( '::' ) ;
105+
106+ if ( seen . has ( key ) ) {
107+ return ;
108+ }
109+
110+ seen . add ( key ) ;
111+ merged . push ( finding ) ;
112+ } ) ;
113+
114+ return merged ;
115+ }
116+
117+ function analyzeFile ( filePath , options = { } ) {
118+ const { includePatternChecks = true } = options ;
119+ const content = fs . readFileSync ( filePath , 'utf8' ) ;
120+ const findings = mergeFindings (
121+ buildCopyFindings ( content , filePath ) ,
122+ analyzeStructure ( content , filePath ) ,
123+ includePatternChecks ? lintPatterns . checkFile ( filePath ) : [ ]
124+ ) ;
96125
97126 const errors = findings . filter ( ( finding ) => finding . tier === 1 ) ;
98127 const warnings = findings . filter ( ( finding ) => finding . tier !== 1 ) ;
@@ -143,12 +172,12 @@ function runFixtureMode() {
143172 collectFixtureFiles ( FAIL_FIXTURE_DIR ) . forEach ( ( filePath ) => {
144173 const expectedPath = path . join ( EXPECTED_DIR , `${ path . basename ( filePath , '.mdx' ) } .json` ) ;
145174 if ( ! fs . existsSync ( expectedPath ) ) {
146- warnings . push ( `${ path . basename ( filePath ) } skipped: no expected fixture JSON ` ) ;
175+ errors . push ( `Missing expected output file for fixture: ${ path . basename ( filePath ) } ` ) ;
147176 return ;
148177 }
149178
150179 const expected = JSON . parse ( fs . readFileSync ( expectedPath , 'utf8' ) ) ;
151- const result = analyzeFile ( filePath ) ;
180+ const result = analyzeFile ( filePath , { includePatternChecks : true } ) ;
152181 const allExpectedFindings = Array . isArray ( expected . errors ) ? expected . errors : [ ] ;
153182 const requiredFindings = allExpectedFindings . filter ( ( entry ) => entry . required !== false ) ;
154183
@@ -174,23 +203,6 @@ function runFixtureMode() {
174203 }
175204 } ) ;
176205
177- const conditionalFixture = path . join ( FAIL_FIXTURE_DIR , 'conditional-if.mdx' ) ;
178- const conditionalResults = lintPatterns . checkFile ( conditionalFixture ) ;
179- if ( ! conditionalResults . some ( ( finding ) => finding . id === 'CONDITIONAL_IF' ) ) {
180- errors . push ( 'conditional-if.mdx should trigger CONDITIONAL_IF in lint-patterns.js' ) ;
181- }
182-
183- const notFixture = path . join ( FAIL_FIXTURE_DIR , 'not-construction.mdx' ) ;
184- const notResults = lintPatterns . checkFile ( notFixture ) ;
185- if ( ! notResults . some ( ( finding ) => finding . id === 'NOT_CONSTRUCTION' ) ) {
186- errors . push ( 'not-construction.mdx should trigger NOT_CONSTRUCTION in lint-patterns.js' ) ;
187- }
188-
189- const observer = patternObserver . collectPatternCounts ( [ conditionalFixture , notFixture ] ) ;
190- if ( ! observer . counts . CONDITIONAL_IF || ! observer . counts . NOT_CONSTRUCTION ) {
191- errors . push ( 'pattern-observer should aggregate conditional-if and not-construction fixtures' ) ;
192- }
193-
194206 return {
195207 errors,
196208 warnings,
0 commit comments