1
1
'use babel' ;
2
2
3
3
import { join } from 'path' ;
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
5
import { remove } from 'fs-extra' ;
5
6
6
- const validPath = join ( __dirname , 'fixtures' , 'valid.ex' ) ;
7
- const warningPath = join ( __dirname , 'fixtures' , 'proj ' , 'lib' , 'proj .ex') ;
8
- const errorMode1Path = join ( __dirname , 'fixtures' , 'error-mode1.ex' ) ;
9
- const errorMode2Path = join ( __dirname , 'fixtures' , 'error-mode2.ex' ) ;
10
- const exsFilePath = join ( __dirname , 'fixtures' , 'script.exs' ) ;
7
+ const validPathElixirc = join ( __dirname , 'fixtures' , 'elixirc ', 'valid.ex' ) ;
8
+ const warningPathElixirc = join ( __dirname , 'fixtures' , 'elixirc ' , 'warning .ex' ) ;
9
+ const errorMode1PathElixirc = join ( __dirname , 'fixtures' , 'elixirc ', 'error-mode1.ex' ) ;
10
+ const errorMode2PathElixirc = join ( __dirname , 'fixtures' , 'elixirc ', 'error-mode2.ex' ) ;
11
+ const exsFilePathElixirc = join ( __dirname , 'fixtures' , 'elixirc ', 'script.exs' ) ;
11
12
12
- const mixBuildDirectory = join ( __dirname , 'fixtures' , 'proj' , '_build' ) ;
13
+ const validPathMix = join ( __dirname , 'fixtures' , 'mix-proj' , 'lib' , 'valid.ex' ) ;
14
+ const warningPathMix = join ( __dirname , 'fixtures' , 'mix-proj' , 'lib' , 'warning.ex' ) ;
15
+ const errorMode1PathMix = join ( __dirname , 'fixtures' , 'mix-proj' , 'lib' , 'error-mode1.ex' ) ;
16
+ const errorMode2PathMix = join ( __dirname , 'fixtures' , 'mix-proj' , 'lib' , 'error-mode2.ex' ) ;
17
+ const exsFilePathMix = join ( __dirname , 'fixtures' , 'mix-proj' , 'lib' , 'script.exs' ) ;
18
+
19
+ const mixBuildDirectory = join ( __dirname , 'fixtures' , 'mix-proj' , '_build' ) ;
13
20
remove ( mixBuildDirectory ) ;
14
21
15
22
describe ( 'The elixirc provider for Linter' , ( ) => {
16
- describe ( 'when using the standard configuration' , ( ) => {
17
- let lint ;
18
-
19
- beforeEach ( ( ) => {
20
- atom . config . set ( 'linter-elixirc.forceElixirc' , false ) ;
21
- lint = require ( '../lib/init.js' ) . provideLinter ( ) . lint ;
22
- atom . workspace . destroyActivePaneItem ( ) ;
23
-
24
- waitsForPromise ( ( ) =>
25
- Promise . all ( [
26
- atom . packages . activatePackage ( 'linter-elixirc' ) ,
27
- atom . packages . activatePackage ( 'language-elixir' ) ,
28
- ] ) ,
29
- ) ;
30
- } ) ;
31
-
32
- it ( 'works with mode 1 errors' , ( ) => {
33
- waitsForPromise ( ( ) =>
34
- atom . workspace . open ( errorMode1Path ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
35
- expect ( messages . length ) . toBe ( 1 ) ;
36
- expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
37
- expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
38
- expect ( messages [ 0 ] . excerpt ) . toBe ( '(ArgumentError) Dangerous is not available' ) ;
39
- expect ( messages [ 0 ] . location . file ) . toBe ( errorMode1Path ) ;
40
- expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 1 , 0 ] , [ 1 , 32 ] ] ) ;
41
- } ) ,
42
- ) ;
43
- } ) ;
44
-
45
- it ( 'works with mode 1 errors for elixirc' , ( ) => {
46
- waitsForPromise ( ( ) =>
47
- atom . workspace . open ( errorMode1Path ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
48
- expect ( messages . length ) . toBe ( 1 ) ;
49
- expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
50
- expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
51
- expect ( messages [ 0 ] . excerpt ) . toBe ( '(ArgumentError) Dangerous is not available' ) ;
52
- expect ( messages [ 0 ] . location . file ) . toBe ( errorMode1Path ) ;
53
- expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 1 , 0 ] , [ 1 , 32 ] ] ) ;
54
- } ) ,
55
- ) ;
56
- } ) ;
57
-
58
- it ( 'works with mode 2 errors' , ( ) => {
59
- waitsForPromise ( ( ) =>
60
- atom . workspace . open ( errorMode2Path ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
61
- expect ( messages . length ) . toBe ( 1 ) ;
62
- expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
63
- expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
64
- expect ( messages [ 0 ] . excerpt ) . toBe ( '(CompileError) module Usefulness is not loaded and could not be found' ) ;
65
- expect ( messages [ 0 ] . location . file ) . toBe ( errorMode2Path ) ;
66
- expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 3 , 2 ] , [ 3 , 20 ] ] ) ;
67
- } ) ,
68
- ) ;
69
- } ) ;
70
-
71
- it ( 'works with warnings' , ( ) => {
72
- waitsForPromise ( ( ) =>
73
- atom . workspace . open ( warningPath ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
74
- expect ( messages . length ) . toBe ( 1 ) ;
75
- expect ( messages [ 0 ] . severity ) . toBe ( 'warning' ) ;
76
- expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
77
- expect ( messages [ 0 ] . excerpt ) . toBe ( 'variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name' ) ;
78
- expect ( messages [ 0 ] . location . file ) . toBe ( warningPath ) ;
79
- expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 20 , 4 ] , [ 20 , 20 ] ] ) ;
80
- } ) ,
81
- ) ;
82
- } ) ;
83
-
84
- it ( 'works with .exs files' , ( ) => {
85
- waitsForPromise ( ( ) =>
86
- atom . workspace . open ( exsFilePath ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
87
- expect ( messages . length ) . toBe ( 1 ) ;
88
- expect ( messages [ 0 ] . severity ) . toBe ( 'warning' ) ;
89
- expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
90
- expect ( messages [ 0 ] . excerpt ) . toBe ( 'function simple_function/0 is unused' ) ;
91
- expect ( messages [ 0 ] . location . file ) . toBe ( exsFilePath ) ;
92
- expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 1 , 2 ] , [ 1 , 25 ] ] ) ;
93
- } ) ,
94
- ) ;
23
+ describe ( 'when not working inside a Mix project' , ( ) => {
24
+ describe ( 'and using the standard configuration' , ( ) => {
25
+ let lint ;
26
+
27
+ beforeEach ( ( ) => {
28
+ lint = require ( '../lib/init.js' ) . provideLinter ( ) . lint ;
29
+ atom . workspace . destroyActivePaneItem ( ) ;
30
+
31
+ waitsForPromise ( ( ) =>
32
+ Promise . all ( [
33
+ atom . packages . activatePackage ( 'linter-elixirc' ) ,
34
+ atom . packages . activatePackage ( 'language-elixir' ) ,
35
+ ] ) ,
36
+ ) ;
37
+ } ) ;
38
+
39
+ it ( 'works with mode 1 errors' , ( ) => {
40
+ waitsForPromise ( ( ) =>
41
+ atom . workspace . open ( errorMode1PathElixirc ) . then ( editor =>
42
+ lint ( editor ) ) . then ( ( messages ) => {
43
+ expect ( messages . length ) . toBe ( 1 ) ;
44
+ expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
45
+ expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
46
+ expect ( messages [ 0 ] . excerpt ) . toBe ( '(ArgumentError) Dangerous is not available' ) ;
47
+ expect ( messages [ 0 ] . location . file ) . toBe ( errorMode1PathElixirc ) ;
48
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 1 , 0 ] , [ 1 , 32 ] ] ) ;
49
+ } ) ,
50
+ ) ;
51
+ } ) ;
52
+
53
+ it ( 'works with mode 2 errors' , ( ) => {
54
+ waitsForPromise ( ( ) =>
55
+ atom . workspace . open ( errorMode2PathElixirc ) . then ( editor =>
56
+ lint ( editor ) ) . then ( ( messages ) => {
57
+ expect ( messages . length ) . toBe ( 1 ) ;
58
+ expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
59
+ expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
60
+ expect ( messages [ 0 ] . excerpt ) . toBe ( '(CompileError) module Usefulness is not loaded and could not be found' ) ;
61
+ expect ( messages [ 0 ] . location . file ) . toBe ( errorMode2PathElixirc ) ;
62
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 3 , 2 ] , [ 3 , 20 ] ] ) ;
63
+ } ) ,
64
+ ) ;
65
+ } ) ;
66
+
67
+ it ( 'works with warnings' , ( ) => {
68
+ waitsForPromise ( ( ) =>
69
+ atom . workspace . open ( warningPathElixirc ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
70
+ expect ( messages . length ) . toBe ( 1 ) ;
71
+ expect ( messages [ 0 ] . severity ) . toBe ( 'warning' ) ;
72
+ expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
73
+ expect ( messages [ 0 ] . excerpt ) . toBe ( 'variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name' ) ;
74
+ expect ( messages [ 0 ] . location . file ) . toBe ( warningPathElixirc ) ;
75
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 20 , 4 ] , [ 20 , 20 ] ] ) ;
76
+ } ) ,
77
+ ) ;
78
+ } ) ;
79
+
80
+ it ( 'works with .exs files' , ( ) => {
81
+ waitsForPromise ( ( ) =>
82
+ atom . workspace . open ( exsFilePathElixirc ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
83
+ expect ( messages . length ) . toBe ( 1 ) ;
84
+ expect ( messages [ 0 ] . severity ) . toBe ( 'warning' ) ;
85
+ expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
86
+ expect ( messages [ 0 ] . excerpt ) . toBe ( 'function simple_function/0 is unused' ) ;
87
+ expect ( messages [ 0 ] . location . file ) . toBe ( exsFilePathElixirc ) ;
88
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 1 , 2 ] , [ 1 , 25 ] ] ) ;
89
+ } ) ,
90
+ ) ;
91
+ } ) ;
92
+
93
+ it ( 'finds nothing wrong with a valid file' , ( ) => {
94
+ waitsForPromise ( ( ) =>
95
+ atom . workspace . open ( validPathElixirc ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
96
+ expect ( messages . length ) . toBe ( 0 ) ;
97
+ } ) ,
98
+ ) ;
99
+ } ) ;
95
100
} ) ;
101
+ } ) ;
96
102
97
- it ( 'finds nothing wrong with a valid file' , ( ) => {
98
- waitsForPromise ( ( ) =>
99
- atom . workspace . open ( validPath ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
100
- expect ( messages . length ) . toBe ( 0 ) ;
101
- } ) ,
102
- ) ;
103
+ describe ( 'when working inside a Mix project' , ( ) => {
104
+ describe ( 'and using the standard configuration' , ( ) => {
105
+ let lint ;
106
+
107
+ beforeEach ( ( ) => {
108
+ lint = require ( '../lib/init.js' ) . provideLinter ( ) . lint ;
109
+ atom . workspace . destroyActivePaneItem ( ) ;
110
+
111
+ waitsForPromise ( ( ) =>
112
+ Promise . all ( [
113
+ atom . packages . activatePackage ( 'linter-elixirc' ) ,
114
+ atom . packages . activatePackage ( 'language-elixir' ) ,
115
+ ] ) ,
116
+ ) ;
117
+ } ) ;
118
+
119
+ it ( 'works with mode 2 errors' , ( ) => {
120
+ waitsForPromise ( ( ) =>
121
+ atom . workspace . open ( errorMode2PathMix ) . then ( editor =>
122
+ lint ( editor ) ) . then ( ( messages ) => {
123
+ expect ( messages . length ) . toBe ( 1 ) ;
124
+ expect ( messages [ 0 ] . severity ) . toBe ( 'error' ) ;
125
+ expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
126
+ expect ( messages [ 0 ] . excerpt ) . toBe ( '(CompileError) Identicon.Image.__struct__/1 is undefined, cannot expand struct Identicon.Image' ) ;
127
+ expect ( messages [ 0 ] . location . file ) . toBe ( errorMode2PathMix ) ;
128
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 11 , 4 ] , [ 11 , 30 ] ] ) ;
129
+ } ) ,
130
+ ) ;
131
+ } ) ;
132
+
133
+ it ( 'works with .exs files' , ( ) => {
134
+ waitsForPromise ( ( ) =>
135
+ atom . workspace . open ( exsFilePathMix ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
136
+ expect ( messages . length ) . toBe ( 1 ) ;
137
+ expect ( messages [ 0 ] . severity ) . toBe ( 'warning' ) ;
138
+ expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
139
+ expect ( messages [ 0 ] . excerpt ) . toBe ( 'function simple_function/0 is unused' ) ;
140
+ expect ( messages [ 0 ] . location . file ) . toBe ( exsFilePathMix ) ;
141
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 1 , 2 ] , [ 1 , 25 ] ] ) ;
142
+ } ) ,
143
+ ) ;
144
+ } ) ;
103
145
} ) ;
104
146
} ) ;
105
147
} ) ;
@@ -122,13 +164,13 @@ describe('when using the setting forceElixirc', () => {
122
164
123
165
it ( 'works with warnings' , ( ) => {
124
166
waitsForPromise ( ( ) =>
125
- atom . workspace . open ( warningPath ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
167
+ atom . workspace . open ( errorMode2PathMix ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
126
168
expect ( messages . length ) . toBe ( 1 ) ;
127
- expect ( messages [ 0 ] . severity ) . toBe ( 'warning ' ) ;
169
+ expect ( messages [ 0 ] . severity ) . toBe ( 'error ' ) ;
128
170
expect ( messages [ 0 ] . html ) . not . toBeDefined ( ) ;
129
- expect ( messages [ 0 ] . excerpt ) . toBe ( 'variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name ' ) ;
130
- expect ( messages [ 0 ] . location . file ) . toBe ( warningPath ) ;
131
- expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 20 , 4 ] , [ 20 , 20 ] ] ) ;
171
+ expect ( messages [ 0 ] . excerpt ) . toBe ( '(CompileError) Identicon.Image.__struct__/1 is undefined, cannot expand struct Identicon.Image ' ) ;
172
+ expect ( messages [ 0 ] . location . file ) . toBe ( errorMode2PathMix ) ;
173
+ expect ( messages [ 0 ] . location . position ) . toEqual ( [ [ 11 , 4 ] , [ 11 , 30 ] ] ) ;
132
174
} ) ,
133
175
) ;
134
176
} ) ;
0 commit comments