(_program: Command)
| 129 | * Creates the lint action - checks for issues in a .deepnote file or integrations yaml file. |
| 130 | */ |
| 131 | export function createLintAction(_program: Command): (path: string | undefined, options: LintOptions) => Promise<void> { |
| 132 | return async (path, options) => { |
| 133 | try { |
| 134 | debug(`Linting: ${path}`) |
| 135 | let result: LintFileResult |
| 136 | if (path != null && isYamlPath(path)) { |
| 137 | // The YAML file itself is the integrations file, so --integrations-file has no meaning here. |
| 138 | if (options.integrationsFile) { |
| 139 | warn('Warning: --integrations-file is ignored when linting an integrations YAML file directly') |
| 140 | } |
| 141 | result = await lintIntegrationsFile(path) |
| 142 | } else { |
| 143 | result = await lintFile(path, options) |
| 144 | } |
| 145 | outputLintResult(result, options) |
| 146 | |
| 147 | // Exit with error code if there are notebook errors or configuration errors |
| 148 | const hasErrors = result.issueCount.errors > 0 || result.integrationsFile.issues.length > 0 |
| 149 | if (hasErrors) { |
| 150 | process.exit(ExitCode.Error) |
| 151 | } |
| 152 | } catch (error) { |
| 153 | const message = error instanceof Error ? error.message : String(error) |
| 154 | const exitCode = |
| 155 | error instanceof FileResolutionError || error instanceof InitNotebookResolutionError |
| 156 | ? ExitCode.InvalidUsage |
| 157 | : ExitCode.Error |
| 158 | |
| 159 | if (options.output === 'json') { |
| 160 | outputJson({ success: false, error: message }) |
| 161 | } else { |
| 162 | logError(message) |
| 163 | } |
| 164 | process.exit(exitCode) |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | async function lintFile(path: string | undefined, options: LintOptions): Promise<LintFileResult> { |
| 170 | // Loading `.env` and injecting integration env vars mutates `process.env`; restore it afterwards |
no test coverage detected