File tree Expand file tree Collapse file tree
tests/lib/rules-preprocessor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ const util = require('ember-template-imports/src/util');
99const TRANSFORM_CACHE = new Map ( ) ;
1010const TEXT_CACHE = new Map ( ) ;
1111
12+ // source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
13+ function escapeRegExp ( string ) {
14+ return string . replace ( / [ $ ( ) * + . ? [ \\ \] ^ { | } ] / g, '\\$&' ) ; // $& means the whole matched string
15+ }
16+
1217/**
1318 * This function is responsible for running the embedded templates transform
1419 * from ember-template-imports.
@@ -122,7 +127,7 @@ function mapRange(messages, filename) {
122127 let originalColumnNumber = 0 ;
123128
124129 for ( const [ index , line ] of originalLines . entries ( ) ) {
125- const column = line . search ( new RegExp ( `\\b${ token } \\b` ) ) ;
130+ const column = line . search ( new RegExp ( `\\b${ escapeRegExp ( token ) } \\b` ) ) ;
126131 if ( column > - 1 ) {
127132 originalLineNumber = index + 1 ;
128133 originalColumnNumber = column + 1 ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ function initESLint(options) {
3535 plugins : [ 'ember' ] ,
3636 extends : [ 'plugin:ember/recommended' ] ,
3737 rules : {
38+ 'lines-between-class-members' : 'error' ,
3839 'no-undef' : 'error' ,
3940 'ember/no-get' : 'off' ,
4041 'ember/no-array-prototype-extensions' : 'error' ,
@@ -254,3 +255,30 @@ describe('line/col numbers should be correct', () => {
254255 } ) ;
255256 } ) ;
256257} ) ;
258+
259+ describe ( 'lint errors on the exact line as the <template> tag' , ( ) => {
260+ it ( 'correctly outputs the lint error' , async ( ) => {
261+ const eslint = initESLint ( ) ;
262+ const code = `
263+ import Component from '@glimmer/component';
264+
265+ export default class MyComponent extends Component {
266+ constructor() {
267+ super(...arguments);
268+ }
269+
270+ foo = 'bar';
271+ <template>
272+ <div>
273+ some totally random, non-meaningful text
274+ </div>
275+ </template>
276+ }
277+ ` ;
278+ const results = await eslint . lintText ( code , { filePath : 'my-component.gjs' } ) ;
279+
280+ const resultErrors = results . flatMap ( ( result ) => result . messages ) ;
281+ expect ( resultErrors ) . toHaveLength ( 1 ) ;
282+ expect ( resultErrors [ 0 ] . message ) . toBe ( 'Expected blank line between class members.' ) ;
283+ } ) ;
284+ } ) ;
You can’t perform that action at this time.
0 commit comments