diff --git a/scripts/commands/channels/lint.mts b/scripts/commands/channels/lint.mts index ad27fcb6..6dd12108 100644 --- a/scripts/commands/channels/lint.mts +++ b/scripts/commands/channels/lint.mts @@ -76,6 +76,18 @@ async function main() { localErrors = localErrors.concat(error.details) } + xml.split('\n').forEach((line: string, lineIndex: number) => { + const found = line.match(/='/) + if (found) { + const colIndex = found.index || 0 + localErrors.push({ + line: lineIndex + 1, + col: colIndex + 1, + message: 'Single quotes cannot be used in attributes' + }) + } + }) + if (localErrors.length) { console.log(`\n${chalk.underline(filepath)}`) localErrors.forEach((error: ErrorDetail) => { diff --git a/tests/__data__/input/channels-lint/single_quotes.channels.xml b/tests/__data__/input/channels-lint/single_quotes.channels.xml new file mode 100644 index 00000000..a95422cd --- /dev/null +++ b/tests/__data__/input/channels-lint/single_quotes.channels.xml @@ -0,0 +1,4 @@ + + + Bravo 2 + \ No newline at end of file diff --git a/tests/__data__/input/channels-lint/valid.channels.xml b/tests/__data__/input/channels-lint/valid.channels.xml new file mode 100644 index 00000000..8c499450 --- /dev/null +++ b/tests/__data__/input/channels-lint/valid.channels.xml @@ -0,0 +1,4 @@ + + + Bravo's + \ No newline at end of file diff --git a/tests/commands/channels/lint.test.ts b/tests/commands/channels/lint.test.ts index 2ba65d80..501b6989 100644 --- a/tests/commands/channels/lint.test.ts +++ b/tests/commands/channels/lint.test.ts @@ -53,4 +53,31 @@ describe('channels:lint', () => { expect((error as ExecError).stdout).toContain('2 error(s)') } }) + + it('will show a message if the file contains single quotes', () => { + try { + const cmd = + 'npm run channels:lint --- tests/__data__/input/channels-lint/single_quotes.channels.xml' + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(cmd, stdout) + process.exit(1) + } catch (error) { + expect((error as ExecError).status).toBe(1) + expect((error as ExecError).stdout).toContain('single_quotes.channels.xml') + expect((error as ExecError).stdout).toContain( + '1:14 Single quotes cannot be used in attributes' + ) + } + }) + + it('does not display errors if there are none', () => { + try { + const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/valid.channels.xml' + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(cmd, stdout) + } catch (error) { + if (process.env.DEBUG === 'true') console.log((error as ExecError).stdout) + process.exit(1) + } + }) })