3
3
import * as path from 'path' ;
4
4
import * as fs from 'fs' ;
5
5
import { tmpdir } from 'os' ;
6
- // import rimraf from 'rimraf';
6
+ import rimraf from 'rimraf' ;
7
7
import linterEslintNode from '../lib/main' ;
8
8
9
9
const fixturesDir = path . join ( __dirname , 'fixtures' ) ;
@@ -146,23 +146,23 @@ describe('The eslint provider for Linter', () => {
146
146
const messages = await lint ( editor ) ;
147
147
expect ( messages . length ) . toBe ( 2 ) ;
148
148
149
- const expected0 = "[no-undef] 'foo' is not defined." ;
150
- // TODO: const expected0Url = 'https://eslint.org/docs/rules/no-undef';
151
- const expected1 = '[semi] Extra semicolon.' ;
152
- // TODO: const expected1Url = 'https://eslint.org/docs/rules/semi';
149
+ const expected0 = "'foo' is not defined. (no-undef) " ;
150
+ const expected0Url = 'https://eslint.org/docs/rules/no-undef' ;
151
+ const expected1 = 'Extra semicolon. (semi) ' ;
152
+ const expected1Url = 'https://eslint.org/docs/rules/semi' ;
153
153
154
154
console . log ( messages ) ;
155
155
156
156
expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
157
157
expect ( messages [ 0 ] . excerpt ) . toBe ( expected0 ) ;
158
- // TODO: expect(messages[0].url).toBe(expected0Url);
158
+ expect ( messages [ 0 ] . url ) . toBe ( expected0Url ) ;
159
159
expect ( messages [ 0 ] . location . file ) . toBe ( paths . bad ) ;
160
160
expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 0 , 0 ] , [ 0 , 3 ] ] ) ;
161
161
expect ( messages [ 0 ] . solutions ) . not . toBeDefined ( ) ;
162
162
163
163
expect ( messages [ 1 ] . severity ) . toBe ( 'error' ) ;
164
164
expect ( messages [ 1 ] . excerpt ) . toBe ( expected1 ) ;
165
- // TODO: expect(messages[1].url).toBe(expected1Url);
165
+ expect ( messages [ 1 ] . url ) . toBe ( expected1Url ) ;
166
166
expect ( messages [ 1 ] . location . file ) . toBe ( paths . bad ) ;
167
167
expect ( messages [ 1 ] . location . position ) . toEqual ( [ [ 0 , 8 ] , [ 0 , 9 ] ] ) ;
168
168
expect ( messages [ 1 ] . solutions . length ) . toBe ( 1 ) ;
@@ -207,13 +207,13 @@ describe('The eslint provider for Linter', () => {
207
207
it ( 'shows a message for an invalid import' , async ( ) => {
208
208
const editor = await atom . workspace . open ( paths . badImport ) ;
209
209
const messages = await lint ( editor ) ;
210
- const expected = "[import/no-unresolved] Unable to resolve path to module '../nonexistent'." ;
211
- // TODO: const expectedUrlRegEx = /https[\S]+eslint-plugin-import[\S]+no-unresolved.md/;
210
+ const expected = "Unable to resolve path to module '../nonexistent'. (import/no-unresolved) " ;
211
+ const expectedUrlRegEx = / h t t p s [ \S ] + e s l i n t - p l u g i n - i m p o r t [ \S ] + n o - u n r e s o l v e d .m d / ;
212
212
213
213
expect ( messages . length ) . toBe ( 1 ) ;
214
214
expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
215
215
expect ( messages [ 0 ] . excerpt ) . toBe ( expected ) ;
216
- // TODO: expect(messages[0].url).toMatch(expectedUrlRegEx);
216
+ expect ( messages [ 0 ] . url ) . toMatch ( expectedUrlRegEx ) ;
217
217
expect ( messages [ 0 ] . location . file ) . toBe ( paths . badImport ) ;
218
218
expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 0 , 24 ] , [ 0 , 40 ] ] ) ;
219
219
expect ( messages [ 0 ] . solutions ) . not . toBeDefined ( ) ;
@@ -369,22 +369,22 @@ describe('The eslint provider for Linter', () => {
369
369
let expectedPath ;
370
370
371
371
const checkNoConsole = ( message ) => {
372
- const text = '[no-console] Unexpected console statement.' ;
373
- // TODO: const url = 'https://eslint.org/docs/rules/no-console';
372
+ const text = 'Unexpected console statement. (no-console) ' ;
373
+ const url = 'https://eslint.org/docs/rules/no-console' ;
374
374
expect ( message . severity ) . toBe ( 'error' ) ;
375
375
expect ( message . excerpt ) . toBe ( text ) ;
376
- // TODO: expect(message.url).toBe(url);
376
+ expect ( message . url ) . toBe ( url ) ;
377
377
expect ( message . location . file ) . toBe ( expectedPath ) ;
378
378
expect ( message . location . position ) . toEqual ( [ [ 0 , 0 ] , [ 0 , 11 ] ] ) ;
379
379
} ;
380
380
381
381
const checkNoTrailingSpace = ( message ) => {
382
- const text = '[no-trailing-spaces] Trailing spaces not allowed.' ;
383
- // TODO: const url = 'https://eslint.org/docs/rules/no-trailing-spaces';
382
+ const text = 'Trailing spaces not allowed. (no-trailing-spaces) ' ;
383
+ const url = 'https://eslint.org/docs/rules/no-trailing-spaces' ;
384
384
385
385
expect ( message . severity ) . toBe ( 'error' ) ;
386
386
expect ( message . excerpt ) . toBe ( text ) ;
387
- // TODO: expect(message.url).toBe(url);
387
+ expect ( message . url ) . toBe ( url ) ;
388
388
expect ( message . location . file ) . toBe ( expectedPath ) ;
389
389
expect ( message . location . position ) . toEqual ( [ [ 1 , 9 ] , [ 1 , 10 ] ] ) ;
390
390
} ;
@@ -527,12 +527,12 @@ describe('The eslint provider for Linter', () => {
527
527
it ( 'handles ranges in messages' , async ( ) => {
528
528
const editor = await atom . workspace . open ( paths . endRange ) ;
529
529
const messages = await lint ( editor ) ;
530
- const expected = '[no-unreachable] Unreachable code.' ;
531
- // TODO: const expectedUrl = 'https://eslint.org/docs/rules/no-unreachable';
530
+ const expected = 'Unreachable code. (no-unreachable) ' ;
531
+ const expectedUrl = 'https://eslint.org/docs/rules/no-unreachable' ;
532
532
533
533
expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
534
534
expect ( messages [ 0 ] . excerpt ) . toBe ( expected ) ;
535
- // TODO: expect(messages[0].url).toBe(expectedUrl);
535
+ expect ( messages [ 0 ] . url ) . toBe ( expectedUrl ) ;
536
536
expect ( messages [ 0 ] . location . file ) . toBe ( paths . endRange ) ;
537
537
expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 5 , 2 ] , [ 6 , 15 ] ] ) ;
538
538
} ) ;
@@ -573,28 +573,27 @@ describe('The eslint provider for Linter', () => {
573
573
// });
574
574
575
575
// TODO:
576
- // describe('when `disableWhenNoEslintConfig` is true', () => {
577
- // let editor;
578
- // let tempFixtureDir;
579
- //
580
- // beforeEach(async () => {
581
- // atom.config.set('linter-eslint-node.disabling.disableWhenNoEslintConfig', true);
582
- //
583
- // const tempFilePath = await copyFileToTempDir(paths.badInline);
584
- // editor = await atom.workspace.open(tempFilePath);
585
- // tempFixtureDir = path.dirname(tempFilePath);
586
- // });
587
- //
588
- // afterEach(() => {
589
- // rimraf.sync(tempFixtureDir);
590
- // });
591
- //
592
- // it('does not report errors when no config file is found', async () => {
593
- // const messages = await lint(editor);
594
- //
595
- // expect(messages.length).toBe(0);
596
- // });
597
- // });
576
+ describe ( 'when `disableWhenNoEslintConfig` is true' , ( ) => {
577
+ let editor ;
578
+ let tempFixtureDir ;
579
+
580
+ beforeEach ( async ( ) => {
581
+ atom . config . set ( 'linter-eslint-node.disabling.disableWhenNoEslintConfig' , true ) ;
582
+
583
+ const tempFilePath = await copyFileToTempDir ( paths . badInline ) ;
584
+ editor = await atom . workspace . open ( tempFilePath ) ;
585
+ tempFixtureDir = path . dirname ( tempFilePath ) ;
586
+ } ) ;
587
+
588
+ afterEach ( ( ) => {
589
+ rimraf . sync ( tempFixtureDir ) ;
590
+ } ) ;
591
+
592
+ it ( 'does not report errors when no config file is found' , async ( ) => {
593
+ const messages = await lint ( editor ) ;
594
+ expect ( messages . length ) . toBe ( 0 ) ;
595
+ } ) ;
596
+ } ) ;
598
597
599
598
// TODO:
600
599
// describe('lets ESLint handle configuration', () => {
@@ -686,18 +685,18 @@ describe('The eslint provider for Linter', () => {
686
685
// });
687
686
688
687
describe ( 'handles the Show Rule ID in Messages option' , ( ) => {
689
- // TODO: const expectedUrlRegEx = /https[\S]+eslint-plugin-import[\S]+no-unresolved.md/;
688
+ const expectedUrlRegEx = / h t t p s [ \S ] + e s l i n t - p l u g i n - i m p o r t [ \S ] + n o - u n r e s o l v e d .m d / ;
690
689
691
690
it ( 'shows the rule ID when enabled' , async ( ) => {
692
691
atom . config . set ( 'linter-eslint-node.advanced.showRuleIdInMessage' , true ) ;
693
692
const editor = await atom . workspace . open ( paths . badImport ) ;
694
693
const messages = await lint ( editor ) ;
695
- const expected = "[import/no-unresolved] Unable to resolve path to module '../nonexistent'." ;
694
+ const expected = "Unable to resolve path to module '../nonexistent'. (import/no-unresolved) " ;
696
695
697
696
expect ( messages . length ) . toBe ( 1 ) ;
698
697
expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
699
698
expect ( messages [ 0 ] . excerpt ) . toBe ( expected ) ;
700
- // TODO: expect(messages[0].url).toMatch(expectedUrlRegEx);
699
+ expect ( messages [ 0 ] . url ) . toMatch ( expectedUrlRegEx ) ;
701
700
expect ( messages [ 0 ] . location . file ) . toBe ( paths . badImport ) ;
702
701
expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 0 , 24 ] , [ 0 , 40 ] ] ) ;
703
702
expect ( messages [ 0 ] . solutions ) . not . toBeDefined ( ) ;
@@ -712,7 +711,7 @@ describe('The eslint provider for Linter', () => {
712
711
expect ( messages . length ) . toBe ( 1 ) ;
713
712
expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
714
713
expect ( messages [ 0 ] . excerpt ) . toBe ( expected ) ;
715
- // TODO: expect(messages[0].url).toMatch(expectedUrlRegEx);
714
+ expect ( messages [ 0 ] . url ) . toMatch ( expectedUrlRegEx ) ;
716
715
expect ( messages [ 0 ] . location . file ) . toBe ( paths . badImport ) ;
717
716
expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 0 , 24 ] , [ 0 , 40 ] ] ) ;
718
717
expect ( messages [ 0 ] . solutions ) . not . toBeDefined ( ) ;
@@ -722,17 +721,19 @@ describe('The eslint provider for Linter', () => {
722
721
it ( "registers an 'ESLint Fix' right click menu command" , ( ) => {
723
722
// NOTE: Reaches into the private data of the ContextMenuManager, there is
724
723
// no public method to check this though so...
725
- expect ( atom . contextMenu . itemSets . some ( ( itemSet ) => (
726
- // Matching selector...
727
- itemSet . selector === 'atom-text-editor:not(.mini), .overlayer'
728
- && itemSet . items . some ( ( item ) => (
729
- // Matching command...
730
- item . command === 'linter-eslint:fix-file'
731
- // Matching label
732
- && item . label === 'ESLint Fix'
733
- // And has a function controlling display
734
- && typeof item . shouldDisplay === 'function'
724
+ expect (
725
+ atom . contextMenu . itemSets . some ( ( itemSet ) => (
726
+ // Matching selector...
727
+ itemSet . selector === 'atom-text-editor:not(.mini), .overlayer'
728
+ && itemSet . items . some ( ( item ) => (
729
+ // Matching command...
730
+ item . command === 'linter-eslint:fix-file'
731
+ // Matching label
732
+ && item . label === 'ESLint Fix'
733
+ // And has a function controlling display
734
+ && typeof item . shouldDisplay === 'function'
735
+ ) )
735
736
) )
736
- ) ) ) ;
737
+ ) . toBe ( true ) ;
737
738
} ) ;
738
739
} ) ;
0 commit comments