Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Ignore dotted params #112

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions src/docs-report/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
lookupFile
} from '../utils'
import { EntryPoint } from '../interfaces'
import { readFileSync } from 'fs'

export const generateApiExtractorReport = async (
entryPoint: EntryPoint,
Expand Down Expand Up @@ -78,6 +79,15 @@
const category = getCategoryFromApiExtractor(message.category)
const messageId = message.messageId

// Hack to support destructured param names
// TODO: Watch https://github.com/microsoft/tsdoc/issues/19
if (
messageId === 'tsdoc-param-tag-with-invalid-name' &&
checkIsValidParamName(message)
) {
return
}

const fullMessageId = `${category}:${messageId}`
if (ignoreMessages.includes(fullMessageId)) {
console.info(`Ignoring message: ${fullMessageId}`)
Expand Down Expand Up @@ -220,3 +230,39 @@

return { typings, main }
}

const checkIsValidParamName = (message: ExtractorMessage): boolean => {
const sourceLineWords = readSourceLineWords(
message.sourceFilePath!,

Check warning on line 236 in src/docs-report/api-extractor.ts

View workflow job for this annotation

GitHub Actions / Test Action Pipeline

Forbidden non-null assertion
message.sourceFileLine!,

Check warning on line 237 in src/docs-report/api-extractor.ts

View workflow job for this annotation

GitHub Actions / Test Action Pipeline

Forbidden non-null assertion
message.sourceFileColumn!

Check warning on line 238 in src/docs-report/api-extractor.ts

View workflow job for this annotation

GitHub Actions / Test Action Pipeline

Forbidden non-null assertion
)
if (sourceLineWords.length >= 2) {
const paramName = sourceLineWords[1]
if (isValidParamNameWithDot(paramName)) {
console.info('Ignoring paramName with dotted notation: ', paramName)
return true
}
}
return false
}

const readSourceLineWords = (
filePath: string,
line: number,
column: number
): string => {
const fileContent = readFileSync(filePath, 'utf8')
const lines = fileContent.split('\n')
if (line > lines.length) return ''

const targetLine = lines[line - 1] // Lines are 1-indexed, arrays are 0-indexed
const words = targetLine.slice(column - 1).split(/\s+/) // Columns are 1-indexed
console.info('>>> Words:', words)
return words[0]
}

const isValidParamNameWithDot = (variableName: string): boolean => {
const regex = /^[a-zA-Z_$][\w$]*(\.[a-zA-Z_$][\w$]*)*$/
return regex.test(variableName)
}