flashios09 / extract-tagged-template-literals

Search and extract tagged template literals from javascript/typescript file.
1 stars 1 forks source link

ember-template-lint no-trailing-spaces #1

Open loginovma opened 4 years ago

loginovma commented 4 years ago

Feeding the default component test template to searchAndEtractHbs and then linting with ember-template-lint with eol-last and no-trailing-spaces enabled:

input file:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | template-lint', function(hooks) {
  setupRenderingTest(hooks);

  test('it renders', async function(assert) {
    // Set any properties with this.set('myProperty', 'value');
    // Handle any actions with this.set('myAction', function(val) { ... });

    await render(hbs`<TemplateLint />`);

    assert.equal(this.element.textContent.trim(), '');

    // Template block usage:
    await render(hbs`
      <TemplateLint>
        template block text
      </TemplateLint>
    `);

    assert.equal(this.element.textContent.trim(), 'template block text');
  });
});

linter.verify:

[ { rule: 'eol-last',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'template must end with newline',
    line: 1,
    column: 0,
    source:
     '                                     \n                                                 \n                                             \n                                             \n\n                                                                   \n                            \n\n                                             \n                                                               \n                                                                           \n\n                     <TemplateLint />   \n\n                                                      \n\n                            \n                     \n      <TemplateLint>\n        template block text\n      </TemplateLint>\n     ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 1,
    column: 36,
    source: '                                     ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 2,
    column: 48,
    source: '                                                 ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 3,
    column: 44,
    source: '                                             ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 4,
    column: 44,
    source: '                                             ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 6,
    column: 66,
    source:
     '                                                                   ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 7,
    column: 27,
    source: '                            ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 9,
    column: 44,
    source: '                                             ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 10,
    column: 62,
    source:
     '                                                               ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 11,
    column: 74,
    source:
     '                                                                           ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 13,
    column: 39,
    source: '                     <TemplateLint />   ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 15,
    column: 53,
    source: '                                                      ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 17,
    column: 27,
    source: '                            ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 18,
    column: 20,
    source: '                     ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 22,
    column: 4,
    source: '     ' } ]

I tried to fix lint errors by changing

inlineTemplate += match.replace(/[ ]|\S/gm, " ");

to

inlineTemplate += match.replace(/[ ]|\S/gm, "");

But that still left me with

[ { rule: 'eol-last',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'template must end with newline',
    line: 1,
    column: 0,
    source:
     '\n\n\n\n\n\n\n\n\n\n\n\n<TemplateLint />\n\n\n\n\n\n      <TemplateLint>\n        template block text\n      </TemplateLint>\n    ' },
  { rule: 'no-trailing-spaces',
    severity: 2,
    moduleId: 'template.hbs',
    message: 'line cannot end with space',
    line: 22,
    column: 3,
    source: '    ' } ]
flashios09 commented 4 years ago

hi @loginovma, i have fixed the no-trailing-spaces ember template lint error, you need to update the Unstable Ember Language Server to 0.2.30.

image

For the eol-last lint rule, i have discussed the issue with Alex(@lifeart), i will try to update the rule https://github.com/ember-template-lint/ember-template-lint/blob/master/lib/rules/lint-eol-last.js to skip it if we have a js/ts file: inline: false.

loginovma commented 4 years ago

Thank you! Blazing fast fix ;)