Skip to content

Commit

Permalink
Disable embedded templates handling for eol-last rule
Browse files Browse the repository at this point in the history
  • Loading branch information
robinborst95 committed Mar 15, 2023
1 parent cdf677a commit cc0929e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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
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) {
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.
{
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

0 comments on commit cc0929e

Please sign in to comment.