* Check a file for version-specific patterns
(filePath)
| 136 | * Check a file for version-specific patterns |
| 137 | */ |
| 138 | function checkFile(filePath) { |
| 139 | const content = fs.readFileSync(filePath, 'utf8'); |
| 140 | const relativePath = path.relative(process.cwd(), filePath); |
| 141 | const issues = []; |
| 142 | |
| 143 | versionSpecificPatterns.forEach((check) => { |
| 144 | const matches = content.match(check.pattern); |
| 145 | if (matches) { |
| 146 | matches.forEach((match) => { |
| 147 | // Get line number |
| 148 | const lines = content.substring(0, content.indexOf(match)).split('\n'); |
| 149 | const lineNumber = lines.length; |
| 150 | |
| 151 | const issue = { |
| 152 | file: relativePath, |
| 153 | line: lineNumber, |
| 154 | pattern: check.name, |
| 155 | match: match.trim(), |
| 156 | since: check.since, |
| 157 | severity: check.severity, |
| 158 | description: check.description, |
| 159 | }; |
| 160 | |
| 161 | if (check.severity === 'error') { |
| 162 | results.errors.push(issue); |
| 163 | results.passed = false; |
| 164 | } else { |
| 165 | results.warnings.push(issue); |
| 166 | } |
| 167 | |
| 168 | issues.push(issue); |
| 169 | }); |
| 170 | } |
| 171 | }); |
| 172 | |
| 173 | return issues; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Print results |