Skip to content

Commit f35d9c3

Browse files
dklilleyGitHub Enterprise
authored andcommitted
Merge pull request mathworks#46 from development/rmohamme.fix-lint-for-ipynb
Add lint support for IPYNB files when MATLAB is connected
2 parents d3444b1 + 0c28417 commit f35d9c3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/providers/linting/LintingSupportProvider.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ class LintingSupportProvider {
9292
const matlabConnection = await this.matlabLifecycleManager.getMatlabConnection()
9393
const isMatlabAvailable = matlabConnection != null
9494

95-
const fileName = URI.parse(uri).fsPath
95+
const isMFile = this.isMFile(uri)
96+
const fileName = isMFile ? URI.parse(uri).fsPath : "untitled.m"
9697

9798
let lintData: string[] = []
9899

99100
if (isMatlabAvailable) {
100101
// Use MATLAB-based linting for better results and fixes
101102
const code = textDocument.getText()
102103
lintData = await this.getLintResultsFromMatlab(code, fileName, matlabConnection)
103-
} else {
104+
} else if (isMFile) {
104105
// Try to use mlint executable for basic linting
105106
lintData = await this.getLintResultsFromExecutable(fileName)
106107
}
@@ -528,6 +529,16 @@ class LintingSupportProvider {
528529
a.severity === b.severity &&
529530
a.source === b.source
530531
}
532+
533+
/**
534+
* Checks if the given URI corresponds to a MATLAB M-file.
535+
*
536+
* @param uri - The URI of the file to check.
537+
* @returns True if the file is a MATLAB M-file (.m), false otherwise.
538+
*/
539+
private isMFile(uri: string): boolean {
540+
return URI.parse(uri).fsPath.endsWith(".m")
541+
}
531542
}
532543

533544
export default LintingSupportProvider

0 commit comments

Comments
 (0)