Visitar URL original
Apply template update: switch to eslint-plugin-perfectionist (#1441) · stringer-rss/stringer@fa2769a · GitHub
Skip to content

Commit fa2769a

Browse files
rails-template-sync[bot]Template Bot
andauthored
Apply template update: switch to eslint-plugin-perfectionist (#1441)
Source: mockdeep/Rails-Template#1369 Co-authored-by: Template Bot <template-bot@users.noreply.github.com>
1 parent 7c5d17e commit fa2769a

7 files changed

Lines changed: 152 additions & 185 deletions

File tree

‎app/javascript/application.ts‎

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ window.$ = $;
2020
Backbone.$ = $;
2121

2222
_.templateSettings = {
23-
interpolate: /\{\{=(.+?)\}\}/g,
24-
evaluate: /\{\{(.+?)\}\}/g
23+
evaluate: /\{\{(.+?)\}\}/g,
24+
interpolate: /\{\{=(.+?)\}\}/g
2525
};
2626

2727
function CSRFToken() {
@@ -35,25 +35,17 @@ function requestHeaders() {
3535
}
3636

3737
var Story = Backbone.Model.extend({
38+
close: function() {
39+
this.set("open", false);
40+
},
41+
3842
defaults: function() {
3943
return {
4044
"open" : false,
4145
"selected" : false
4246
}
4347
},
4448

45-
toggle: function() {
46-
if (this.get("open")) {
47-
this.close();
48-
} else {
49-
this.open();
50-
}
51-
},
52-
53-
shouldSave: function() {
54-
return this.changedAttributes() && this.get("id") > 0;
55-
},
56-
5749
open: function() {
5850
if (!this.get("keep_unread")) this.set("is_read", true);
5951
if (this.shouldSave()) this.save(null, { headers: requestHeaders() });
@@ -68,6 +60,27 @@ var Story = Backbone.Model.extend({
6860
this.set("selected", true);
6961
},
7062

63+
openInTab: function() {
64+
window.open(this.get("permalink"), '_blank');
65+
},
66+
67+
select: function() {
68+
if(this.collection) this.collection.unselectAll();
69+
this.set("selected", true);
70+
},
71+
72+
shouldSave: function() {
73+
return this.changedAttributes() && this.get("id") > 0;
74+
},
75+
76+
toggle: function() {
77+
if (this.get("open")) {
78+
this.close();
79+
} else {
80+
this.open();
81+
}
82+
},
83+
7184
toggleKeepUnread: function() {
7285
if (this.get("keep_unread")) {
7386
this.set("keep_unread", false);
@@ -80,30 +93,13 @@ var Story = Backbone.Model.extend({
8093
if (this.shouldSave()) this.save(null, { headers: requestHeaders() });
8194
},
8295

83-
close: function() {
84-
this.set("open", false);
85-
},
86-
87-
select: function() {
88-
if(this.collection) this.collection.unselectAll();
89-
this.set("selected", true);
90-
},
91-
9296
unselect: function() {
9397
this.set("selected", false);
94-
},
95-
96-
openInTab: function() {
97-
window.open(this.get("permalink"), '_blank');
9898
}
9999
});
100100

101101
var StoryView = Backbone.View.extend({
102-
tagName: "li",
103102
className: "story",
104-
105-
template: "#story-template",
106-
107103
events: {
108104
"click .story-preview" : "storyClicked"
109105
},
@@ -116,11 +112,31 @@ var StoryView = Backbone.View.extend({
116112
this.listenTo(this.model, 'change:is_read', this.itemRead);
117113
this.el.addEventListener('keep-unread-toggle:toggled', (e) => {
118114
var detail = e.detail;
119-
this.model.set({keep_unread: detail.keepUnread, is_read: detail.isRead}, {silent: true});
115+
this.model.set({is_read: detail.isRead, keep_unread: detail.keepUnread}, {silent: true});
120116
this.model.trigger('change:is_read');
121117
});
122118
},
123119

120+
itemOpened: function() {
121+
if (this.model.get("open")) {
122+
this.$el.addClass("open");
123+
$(".story-lead", this.$el).fadeOut(1000);
124+
window.scrollTo(0, this.$el.offset().top);
125+
} else {
126+
this.$el.removeClass("open");
127+
$(".story-lead", this.$el).show();
128+
}
129+
},
130+
131+
itemRead: function() {
132+
this.$el.toggleClass("read", this.model.get("is_read"));
133+
},
134+
135+
itemSelected: function() {
136+
this.$el.toggleClass("cursor", this.model.get("selected"));
137+
if (!this.$el.visible()) window.scrollTo(0, this.$el.offset().top);
138+
},
139+
124140
render: function() {
125141
var jsonModel = this.model.toJSON();
126142
this.$el.html(this.template(jsonModel));
@@ -141,26 +157,6 @@ var StoryView = Backbone.View.extend({
141157
return this;
142158
},
143159

144-
itemRead: function() {
145-
this.$el.toggleClass("read", this.model.get("is_read"));
146-
},
147-
148-
itemOpened: function() {
149-
if (this.model.get("open")) {
150-
this.$el.addClass("open");
151-
$(".story-lead", this.$el).fadeOut(1000);
152-
window.scrollTo(0, this.$el.offset().top);
153-
} else {
154-
this.$el.removeClass("open");
155-
$(".story-lead", this.$el).show();
156-
}
157-
},
158-
159-
itemSelected: function() {
160-
this.$el.toggleClass("cursor", this.model.get("selected"));
161-
if (!this.$el.visible()) window.scrollTo(0, this.$el.offset().top);
162-
},
163-
164160
storyClicked: function(e) {
165161
if (e.metaKey || e.ctrlKey || e.which == 2) {
166162
var backgroundTab = window.open(this.model.get("permalink"));
@@ -174,48 +170,29 @@ var StoryView = Backbone.View.extend({
174170
}
175171
},
176172

177-
});
178-
179-
var StoryList = Backbone.Collection.extend({
180-
model: Story,
181-
url: "/stories",
182-
183-
initialize: function() {
184-
this.cursorPosition = -1;
185-
},
173+
tagName: "li",
186174

187-
max_position: function() {
188-
return this.length - 1;
189-
},
175+
template: "#story-template",
190176

191-
unreadCount: function() {
192-
return this.where({is_read: false}).length;
193-
},
177+
});
194178

179+
var StoryList = Backbone.Collection.extend({
195180
closeOthers: function(modelToSkip) {
196181
this.each(function(model) {
197182
if (model.id != modelToSkip.id) {
198183
model.close();
199184
}
200185
});
201186
},
202-
203-
selected: function() {
204-
return this.where({selected: true});
205-
},
206-
207-
unselectAll: function() {
208-
_.invoke(this.selected(), "unselect");
187+
initialize: function() {
188+
this.cursorPosition = -1;
209189
},
210190

211-
selectedStoryId: function() {
212-
var selectedStory = this.at(this.cursorPosition);
213-
return selectedStory ? selectedStory.id : -1;
191+
max_position: function() {
192+
return this.length - 1;
214193
},
215194

216-
setSelection: function(model) {
217-
this.cursorPosition = this.indexOf(model);
218-
},
195+
model: Story,
219196

220197
moveCursorDown: function() {
221198
if (this.cursorPosition < this.max_position()) {
@@ -241,23 +218,55 @@ var StoryList = Backbone.Collection.extend({
241218
this.at(this.cursorPosition).open();
242219
},
243220

221+
selected: function() {
222+
return this.where({selected: true});
223+
},
224+
225+
selectedStoryId: function() {
226+
var selectedStory = this.at(this.cursorPosition);
227+
return selectedStory ? selectedStory.id : -1;
228+
},
229+
230+
setSelection: function(model) {
231+
this.cursorPosition = this.indexOf(model);
232+
},
233+
244234
toggleCurrent: function() {
245235
if (this.cursorPosition < 0) this.cursorPosition = 0;
246236
this.at(this.cursorPosition).toggle();
247237
},
248238

249-
viewCurrentInTab: function() {
239+
toggleCurrentKeepUnread: function() {
250240
if (this.cursorPosition < 0) this.cursorPosition = 0;
251-
this.at(this.cursorPosition).openInTab();
241+
this.at(this.cursorPosition).toggleKeepUnread();
252242
},
253243

254-
toggleCurrentKeepUnread: function() {
244+
unreadCount: function() {
245+
return this.where({is_read: false}).length;
246+
},
247+
248+
unselectAll: function() {
249+
_.invoke(this.selected(), "unselect");
250+
},
251+
252+
url: "/stories",
253+
254+
viewCurrentInTab: function() {
255255
if (this.cursorPosition < 0) this.cursorPosition = 0;
256-
this.at(this.cursorPosition).toggleKeepUnread();
256+
this.at(this.cursorPosition).openInTab();
257257
}
258258
});
259259

260260
var AppView = Backbone.View.extend({
261+
addAll: function() {
262+
this.stories.each(this.addOne, this);
263+
},
264+
265+
addOne: function(story) {
266+
var view = new StoryView({model: story});
267+
this.$("#story-list").append(view.render().el);
268+
},
269+
261270
el: "#stories",
262271

263272
initialize: function(collection) {
@@ -273,25 +282,6 @@ var AppView = Backbone.View.extend({
273282
this.stories.reset(data);
274283
},
275284

276-
render: function() {
277-
var unreadCount = this.stories.unreadCount();
278-
279-
if (unreadCount === 0) {
280-
document.title = window.i18n.titleName;
281-
} else {
282-
document.title = "(" + unreadCount + ") " + window.i18n.titleName;
283-
}
284-
},
285-
286-
addOne: function(story) {
287-
var view = new StoryView({model: story});
288-
this.$("#story-list").append(view.render().el);
289-
},
290-
291-
addAll: function() {
292-
this.stories.each(this.addOne, this);
293-
},
294-
295285
moveCursorDown: function() {
296286
this.stories.moveCursorDown();
297287
},
@@ -304,16 +294,26 @@ var AppView = Backbone.View.extend({
304294
this.stories.openCurrentSelection();
305295
},
306296

307-
toggleCurrent: function() {
308-
this.stories.toggleCurrent();
297+
render: function() {
298+
var unreadCount = this.stories.unreadCount();
299+
300+
if (unreadCount === 0) {
301+
document.title = window.i18n.titleName;
302+
} else {
303+
document.title = "(" + unreadCount + ") " + window.i18n.titleName;
304+
}
309305
},
310306

311-
viewCurrentInTab: function() {
312-
this.stories.viewCurrentInTab();
307+
toggleCurrent: function() {
308+
this.stories.toggleCurrent();
313309
},
314310

315311
toggleCurrentKeepUnread: function() {
316312
this.stories.toggleCurrentKeepUnread();
313+
},
314+
315+
viewCurrentInTab: function() {
316+
this.stories.viewCurrentInTab();
317317
}
318318
});
319319

‎eslint.config.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import js from "@eslint/js";
55
import stylistic from "@stylistic/eslint-plugin";
66
import tseslint from "typescript-eslint";
77
import {defineConfig} from "eslint/config";
8-
import sortKeysFix from "eslint-plugin-sort-keys-fix";
8+
import perfectionist from "eslint-plugin-perfectionist";
99
import eslintTodo from "./.eslint_todo";
1010

1111
export default defineConfig([
@@ -35,7 +35,7 @@ export default defineConfig([
3535
},
3636
plugins: {
3737
importPlugin,
38-
"sort-keys-fix": sortKeysFix,
38+
perfectionist,
3939
vitest,
4040
},
4141
rules: {
@@ -67,11 +67,11 @@ export default defineConfig([
6767
"no-undefined": "off",
6868
"no-var": "off",
6969
"one-var": ["error", "never"],
70+
"perfectionist/sort-objects":
71+
["error", {ignoreCase: true, order: "asc", type: "natural"}],
7072
"sort-imports":
7173
["error", {ignoreCase: true, ignoreDeclarationSort: true}],
72-
"sort-keys": ["error", "asc", {caseSensitive: false, natural: true}],
73-
"sort-keys-fix/sort-keys-fix":
74-
["error", "asc", {caseSensitive: false, natural: true}],
74+
"sort-keys": "off",
7575
"vitest/consistent-test-it":
7676
["error", {fn: "it", withinDescribe: "it"}],
7777
"vitest/expect-expect": "off",

‎package.json‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
"@types/underscore": "latest",
3131
"@typescript-eslint/eslint-plugin": "^8.57.0",
3232
"@typescript-eslint/parser": "^8.57.0",
33-
"@vitest/coverage-v8": "4.0.18",
33+
"@vitest/coverage-v8": "^4.0.18",
3434
"@vitest/eslint-plugin": "^1.6.10",
3535
"esbuild": "^0.27.1",
3636
"eslint": "^10.0.2",
3737
"eslint-find-rules": "^5.0.0",
3838
"eslint-import-resolver-typescript": "^4.4.4",
3939
"eslint-plugin-import": "^2.32.0",
40-
"eslint-plugin-sort-keys-fix": "^1.1.2",
41-
"globals": "^17.0.0",
40+
"eslint-plugin-perfectionist": "^5.6.0",
41+
"globals": "^17.4.0",
4242
"jiti": "^2.6.1",
4343
"jsdom": "^28.0.0",
4444
"stylelint": "^17.3.0",
@@ -58,10 +58,5 @@
5858
"stylelint": "./node_modules/stylelint/bin/stylelint.mjs 'app/assets/stylesheets/**/*'",
5959
"test": "pnpm vitest run --coverage",
6060
"tscheck": "tsc --noEmit"
61-
},
62-
"pnpm": {
63-
"patchedDependencies": {
64-
"eslint-plugin-sort-keys-fix@1.1.2": "patches/eslint-plugin-sort-keys-fix@1.1.2.patch"
65-
}
6661
}
6762
}

0 commit comments

Comments
 (0)