Skip to content

Commit 0fd40b6

Browse files
committed
Linelint
1 parent 810e093 commit 0fd40b6

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

spec/lexers/glimmer_js_spec.rb

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
it 'lexes JavaScript code outside template blocks' do
2626
assert_has_token 'Keyword', 'import Component from "@glimmer/component";'
27-
assert_has_token 'Name.Class', 'export default class MyComponent extends Component {'
27+
assert_has_token 'Name.Class',
28+
'export default class MyComponent extends Component {'
2829
assert_has_token 'Name.Decorator', '@tracked count = 0;'
2930
end
3031

@@ -36,7 +37,7 @@
3637
it 'lexes handlebars expressions in templates' do
3738
code = '<template><div>{{@name}}</div></template>'
3839
assert_has_token 'Keyword', code # {{ and }}
39-
assert_has_token 'Name.Attribute', code # @name (tokenized as attribute by handlebars)
40+
assert_has_token 'Name.Attribute', code
4041
assert_has_token 'Name.Tag', code # template and div tags
4142
end
4243

@@ -48,7 +49,9 @@
4849
end
4950

5051
it 'lexes handlebars with modifiers' do
51-
code = '<template><button {{on "click" this.handleClick}}>Click</button></template>'
52+
code = '<template>' \
53+
'<button {{on "click" this.handleClick}}>Click</button>' \
54+
'</template>'
5255
assert_has_token 'Keyword', code # {{ and }}
5356
assert_has_token 'Name.Variable', code # on
5457
assert_has_token 'Literal.String.Double', code # "click"
@@ -65,7 +68,7 @@
6568
</template>
6669
}
6770
GJS
68-
71+
6972
assert_has_token 'Keyword', code # export, default, class, extends
7073
assert_has_token 'Name.Class', code # MyComponent, Component
7174
assert_has_token 'Name.Decorator', code # @tracked
@@ -79,14 +82,16 @@
7982
<h1>Hello {{@name}}!</h1>
8083
</template>;
8184
GJS
82-
85+
8386
assert_has_token 'Keyword', code # const
8487
assert_has_token 'Name.Tag', code # <template>, <h1>
8588
assert_has_token 'Name.Attribute', code # @name
8689
end
8790

8891
it 'lexes nested handlebars expressions' do
89-
code = '<template>{{#each @items as |item|}}{{item.name}}{{/each}}</template>'
92+
code = '<template>' \
93+
'{{#each @items as |item|}}{{item.name}}{{/each}}' \
94+
'</template>'
9095
assert_has_token 'Keyword', code # {{#each, {{/each
9196
assert_has_token 'Name.Attribute', code # @items, item.name
9297
assert_has_token 'Name.Tag', code # template
@@ -95,21 +100,21 @@
95100
it 'lexes handlebars with yield' do
96101
code = '<template><div>{{yield}}</div></template>'
97102
assert_has_token 'Keyword', code # {{ and }}
98-
assert_has_token 'Name.Variable', code # yield (tokenized as variable by handlebars)
103+
assert_has_token 'Name.Variable', code
99104
assert_has_token 'Name.Tag', code # template and div
100105
end
101106

102107
it 'lexes mixed JavaScript and template content' do
103108
code = <<~GJS
104109
import { helper } from '@ember/component/helper';
105-
110+
106111
const formatName = helper(([first, last]) => `${first} ${last}`);
107-
112+
108113
<template>
109114
<p>{{formatName @firstName @lastName}}</p>
110115
</template>
111116
GJS
112-
117+
113118
assert_has_token 'Keyword', code # import, const
114119
assert_has_token 'Name.Function', code # helper
115120
assert_has_token 'Name.Tag', code # <template>, <p>
@@ -125,7 +130,7 @@ class MyComponent extends Component {
125130
</template>
126131
}
127132
GJS
128-
133+
129134
# Test that we properly enter and exit template mode
130135
assert_has_token 'Keyword', code # class, extends
131136
assert_has_token 'Name.Tag', code # <template>, <div>
@@ -145,23 +150,31 @@ class MyComponent extends Component {
145150
end
146151

147152
it 'lexes splattributes syntax' do
148-
code = '<template><div class="some-class" ...attributes>{{@someValue}}</div></template>'
153+
code = '<template>' \
154+
'<div class="some-class" ...attributes>{{@someValue}}</div>' \
155+
'</template>'
149156
assert_has_token 'Operator', code # ... operator
150157
assert_has_token 'Name.Attribute', code # attributes and class
151158
assert_has_token 'Name.Tag', code # div tags
152159
assert_has_token 'Name.Attribute', code # @someValue
153160
end
154161

155162
it 'lexes splattributes with other attributes' do
156-
code = '<template><button type="button" ...attributes {{on "click" @onClick}}>Click</button></template>'
163+
code = '<template>' \
164+
'<button type="button" ...attributes {{on "click" @onClick}}>' \
165+
'Click' \
166+
'</button>' \
167+
'</template>'
157168
assert_has_token 'Operator', code # ... operator
158169
assert_has_token 'Name.Attribute', code # type, attributes, on
159170
assert_has_token 'Literal.String', code # "button", "click"
160171
assert_has_token 'Keyword', code # {{ and }}
161172
end
162173

163174
it 'lexes splattributes in different positions' do
164-
code = '<template><input ...attributes type="text" placeholder="Enter text"></template>'
175+
code = '<template>' \
176+
'<input ...attributes type="text" placeholder="Enter text">' \
177+
'</template>'
165178
assert_has_token 'Operator', code # ... operator
166179
assert_has_token 'Name.Attribute', code # attributes, type, placeholder
167180
assert_has_token 'Literal.String', code # "text", "Enter text"

spec/lexers/glimmer_ts_spec.rb

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
it 'lexes TypeScript code outside template blocks' do
2626
assert_has_token 'Keyword', 'import Component from "@glimmer/component";'
27-
assert_has_token 'Name.Class', 'export default class MyComponent extends Component {'
27+
assert_has_token 'Name.Class',
28+
'export default class MyComponent extends Component {'
2829
assert_has_token 'Name.Decorator', '@tracked count: number = 0;'
2930
end
3031

@@ -38,7 +39,7 @@
3839
};
3940
}
4041
GTS
41-
42+
4243
assert_has_token 'Keyword.Reserved', code # interface
4344
assert_has_token 'Name.Other', code # ComponentSignature
4445
assert_has_token 'Keyword.Reserved', code # string, number
@@ -52,7 +53,7 @@
5253
it 'lexes handlebars expressions in templates' do
5354
code = '<template><div>{{@name}}</div></template>'
5455
assert_has_token 'Keyword', code # {{ and }}
55-
assert_has_token 'Name.Attribute', code # @name (tokenized as attribute by handlebars)
56+
assert_has_token 'Name.Attribute', code
5657
assert_has_token 'Name.Tag', code # template and div tags
5758
end
5859

@@ -64,7 +65,9 @@
6465
end
6566

6667
it 'lexes handlebars with modifiers' do
67-
code = '<template><button {{on "click" this.handleClick}}>Click</button></template>'
68+
code = '<template>' \
69+
'<button {{on "click" this.handleClick}}>Click</button>' \
70+
'</template>'
6871
assert_has_token 'Keyword', code # {{ and }}
6972
assert_has_token 'Name.Variable', code # on
7073
assert_has_token 'Literal.String.Double', code # "click"
@@ -76,7 +79,8 @@
7679
Args: { name: string };
7780
}
7881
79-
export default class MyComponent extends Component<MyComponentSignature> {
82+
export default class MyComponent extends
83+
Component<MyComponentSignature> {
8084
@tracked count: number = 0;
8185
8286
get greeting(): string {
@@ -90,7 +94,7 @@
9094
</template>
9195
}
9296
GTS
93-
97+
9498
assert_has_token 'Keyword.Reserved', code # interface
9599
assert_has_token 'Keyword', code # export, default, class, extends, get
96100
assert_has_token 'Name.Class', code # MyComponent, Component
@@ -116,7 +120,7 @@
116120
{{/if}}
117121
</template>;
118122
GTS
119-
123+
120124
assert_has_token 'Keyword', code # import, type, const
121125
assert_has_token 'Keyword.Reserved', code # interface
122126
assert_has_token 'Keyword.Reserved', code # string, boolean
@@ -138,7 +142,7 @@
138142
</template>
139143
}
140144
GTS
141-
145+
142146
assert_has_token 'Keyword.Reserved', code # interface
143147
assert_has_token 'Name.Class', code # List, Component
144148
assert_has_token 'Punctuation', code # <, >, [, ]
@@ -147,14 +151,18 @@
147151
end
148152

149153
it 'lexes nested handlebars expressions' do
150-
code = '<template>{{#each @items as |item|}}{{item.name}}{{/each}}</template>'
154+
code = '<template>' \
155+
'{{#each @items as |item|}}{{item.name}}{{/each}}' \
156+
'</template>'
151157
assert_has_token 'Keyword', code # {{#each, {{/each
152158
assert_has_token 'Name.Attribute', code # @items, item.name
153159
assert_has_token 'Name.Tag', code # template
154160
end
155161

156162
it 'lexes handlebars with yield and blocks' do
157-
code = '<template><div>{{yield (hash name=@name age=@age)}}</div></template>'
163+
code = '<template>' \
164+
'<div>{{yield (hash name=@name age=@age)}}</div>' \
165+
'</template>'
158166
assert_has_token 'Keyword', code # {{ and }}
159167
assert_has_token 'Name.Variable', code # yield, hash
160168
assert_has_token 'Name.Attribute', code # @name, @age
@@ -179,7 +187,7 @@
179187
</template>
180188
}
181189
GTS
182-
190+
183191
assert_has_token 'Keyword.Declaration', code # type
184192
assert_has_token 'Name.Decorator', code # @tracked
185193
assert_has_token 'Name.Other', code # Status (type annotation)
@@ -195,7 +203,7 @@ class MyComponent extends Component {
195203
</template>
196204
}
197205
GTS
198-
206+
199207
# Test that we properly enter and exit template mode
200208
assert_has_token 'Keyword', code # class, extends
201209
assert_has_token 'Name.Tag', code # <template>, <div>
@@ -215,23 +223,31 @@ class MyComponent extends Component {
215223
end
216224

217225
it 'lexes splattributes syntax' do
218-
code = '<template><div class="some-class" ...attributes>{{@someValue}}</div></template>'
226+
code = '<template>' \
227+
'<div class="some-class" ...attributes>{{@someValue}}</div>' \
228+
'</template>'
219229
assert_has_token 'Operator', code # ... operator
220230
assert_has_token 'Name.Attribute', code # attributes and class
221231
assert_has_token 'Name.Tag', code # div tags
222232
assert_has_token 'Name.Attribute', code # @someValue
223233
end
224234

225235
it 'lexes splattributes with other attributes' do
226-
code = '<template><button type="button" ...attributes {{on "click" @onClick}}>Click</button></template>'
236+
code = '<template>' \
237+
'<button type="button" ...attributes {{on "click" @onClick}}>' \
238+
'Click' \
239+
'</button>' \
240+
'</template>'
227241
assert_has_token 'Operator', code # ... operator
228242
assert_has_token 'Name.Attribute', code # type, attributes, on
229243
assert_has_token 'Literal.String', code # "button", "click"
230244
assert_has_token 'Keyword', code # {{ and }}
231245
end
232246

233247
it 'lexes splattributes in different positions' do
234-
code = '<template><input ...attributes type="text" placeholder="Enter text"></template>'
248+
code = '<template>' \
249+
'<input ...attributes type="text" placeholder="Enter text">' \
250+
'</template>'
235251
assert_has_token 'Operator', code # ... operator
236252
assert_has_token 'Name.Attribute', code # attributes, type, placeholder
237253
assert_has_token 'Literal.String', code # "text", "Enter text"
@@ -240,14 +256,15 @@ class MyComponent extends Component {
240256
it 'lexes mixed TypeScript and template content' do
241257
code = <<~GTS
242258
import { helper } from '@ember/component/helper';
243-
244-
const formatName = helper(([first, last]: [string, string]) => `${first} ${last}`);
245-
259+
260+
const formatName = helper(([first, last]: [string, string]) =>
261+
`${first} ${last}`);
262+
246263
<template>
247264
<p>{{formatName @firstName @lastName}}</p>
248265
</template>
249266
GTS
250-
267+
251268
assert_has_token 'Keyword', code # import, const
252269
assert_has_token 'Name.Function', code # helper
253270
assert_has_token 'Keyword.Reserved', code # string

0 commit comments

Comments
 (0)