Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: allow lines to end in <pre> tags #208

Merged
merged 2 commits into from
May 27, 2020
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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ecmarkup",
"version": "3.21.1",
"version": "3.22.0",
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.",
"main": "lib/ecmarkup.js",
"typings": "lib/ecmarkup.d.ts",
Expand Down
17 changes: 16 additions & 1 deletion src/lint/rules/algorithm-line-endings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ export default function (report: (e: LintingError) => void, node: Element): Obse
return;
}

let hasSubsteps = node.sublist !== null;

// Special case: lines without substeps can end in `pre` tags.
if (last.name === 'opaqueTag' && /^\s*<pre>/.test(last.contents)) {
if (hasSubsteps) {
report({
ruleId,
nodeType,
line: node.contents[0].location!.start.line,
column: node.contents[0].location!.start.column,
message: `lines ending in <pre> tags must not have substeps`,
});
}
return;
}

if (last.name !== 'text') {
report({
ruleId,
Expand All @@ -118,7 +134,6 @@ export default function (report: (e: LintingError) => void, node: Element): Obse
}

let initialText = first.name === 'text' ? first.contents : '';
let hasSubsteps = node.sublist !== null;

if (/^(?:If |Else if)/.test(initialText)) {
if (hasSubsteps) {
Expand Down
18 changes: 18 additions & 0 deletions test/lint-algorithm-line-endings.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ describe('linting algorithms', function () {
);
});

it('pre', async function () {
await assertLint(
positioned`<emu-alg>
1. ${M}Let _constructorText_ be the source text
<pre><code class="javascript">constructor() {}</code></pre>
1. Foo.
</emu-alg>`,
{
ruleId,
nodeType,
message: 'lines ending in <pre> tags must not have substeps',
}
);
});

it('negative', async function () {
await assertLintFree(`
<emu-alg>
Expand All @@ -93,6 +108,9 @@ describe('linting algorithms', function () {
1. Other.
1. Other:
1. Substep.
1. Let _constructorText_ be the source text
<pre><code class="javascript">constructor() {}</code></pre>
1. Set _constructor_ to ParseText(_constructorText_, |MethodDefinition[~Yield, ~Await]|).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't strictly needed. I just wanted to confirm that the PR this change is intended to allow will in fact be allowed by it.

</emu-alg>
`);
});
Expand Down