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

Disable embedded templates handling for eol-last rule #2846

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/rule/eol-last.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

🔧 The `--fix` option on the command line can automatically fix some of the problems reported by this rule.

Require or disallow newline at the end of files.
Require or disallow newline at the end of template files. This rule doesn't apply to embedded templates (e.g. a rendered template in a -test.js file).

## Examples

Expand All @@ -25,9 +25,9 @@ or this (with newline at end):

The following values are valid configuration:

- "always" - enforces that files end with a newline
- "always" - enforces that template files end with a newline
- "editorconfig" - requires or disallows final newlines based your projects `.editorconfig` settings (via `insert_final_newline`)
- "never" - enforces that files do not end with a newline'
- "never" - enforces that template files do not end with a newline'

## Related Rules

Expand Down
1 change: 1 addition & 0 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export default class Linter {
filePath: options.filePath,
columnOffset: templateInfo.columnOffset,
rawSource: templateInfo.template,
isStrictMode: templateInfo.isStrictMode,
fileConfig,
});

Expand Down
6 changes: 6 additions & 0 deletions lib/rules/eol-last.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import Rule from './_base.js';

export default class EolLast extends Rule {
parseConfig(config) {
// In strict mode (= template is embedded in e.g. a JS file) we want to disable this rule,
// because it is not meant for templates specifically, but for template files.
if (!this.isStrictMode) {
robinborst95 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Let's also add a note to the rule doc that this rule doesn't apply to embedded templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've adapted the rule doc as well! I figured the rule doc doesn't need an explanation, as it already said files specifically, which I made even more explicit by saying template files instead.

return false;
}

let configType = typeof config;

switch (configType) {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/rules/eol-last-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ generateRuleTests({
config: 'always',
template: '{{#my-component}}{{/my-component}}\n',
},
// test that the config is ignored when the template is embedded, because this rule
// is meant for newlines at the end of files, not for templates themselves.
{
robinborst95 marked this conversation as resolved.
Show resolved Hide resolved
config: 'always',
template: [
"import { hbs } from 'ember-cli-htmlbars';",
'',
"test('it renders', async (assert) => {",
' await render(hbs`<img>`);',
');',
].join('\n'),
meta: {
filePath: 'layout.js',
},
},
],

bad: [
Expand Down