Skip to content

Commit 883a25f

Browse files
authored
DEV: Update linting (#4)
1 parent 7fd9834 commit 883a25f

File tree

14 files changed

+4699
-59
lines changed

14 files changed

+4699
-59
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Discourse Plugin
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
ci:
11+
uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1

.prettierrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("@discourse/lint-configs/prettier");

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inherit_gem:
2+
rubocop-discourse: stree-compat.yml

.streerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--print-width=100
2+
--plugins=plugin/trailing_comma,plugin/disable_auto_ternary

.template-lintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("@discourse/lint-configs/template-lint");

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
group :development do
6+
gem "rubocop-discourse"
7+
gem "syntax_tree"
8+
end

Gemfile.lock

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activesupport (8.0.2)
5+
base64
6+
benchmark (>= 0.3)
7+
bigdecimal
8+
concurrent-ruby (~> 1.0, >= 1.3.1)
9+
connection_pool (>= 2.2.5)
10+
drb
11+
i18n (>= 1.6, < 2)
12+
logger (>= 1.4.2)
13+
minitest (>= 5.1)
14+
securerandom (>= 0.3)
15+
tzinfo (~> 2.0, >= 2.0.5)
16+
uri (>= 0.13.1)
17+
ast (2.4.3)
18+
base64 (0.2.0)
19+
benchmark (0.4.0)
20+
bigdecimal (3.1.9)
21+
concurrent-ruby (1.3.5)
22+
connection_pool (2.5.3)
23+
drb (2.2.1)
24+
i18n (1.14.7)
25+
concurrent-ruby (~> 1.0)
26+
json (2.11.3)
27+
language_server-protocol (3.17.0.4)
28+
lint_roller (1.1.0)
29+
logger (1.7.0)
30+
minitest (5.25.5)
31+
parallel (1.27.0)
32+
parser (3.3.8.0)
33+
ast (~> 2.4.1)
34+
racc
35+
prettier_print (1.2.1)
36+
prism (1.4.0)
37+
racc (1.8.1)
38+
rack (3.1.13)
39+
rainbow (3.1.1)
40+
regexp_parser (2.10.0)
41+
rubocop (1.75.5)
42+
json (~> 2.3)
43+
language_server-protocol (~> 3.17.0.2)
44+
lint_roller (~> 1.1.0)
45+
parallel (~> 1.10)
46+
parser (>= 3.3.0.2)
47+
rainbow (>= 2.2.2, < 4.0)
48+
regexp_parser (>= 2.9.3, < 3.0)
49+
rubocop-ast (>= 1.44.0, < 2.0)
50+
ruby-progressbar (~> 1.7)
51+
unicode-display_width (>= 2.4.0, < 4.0)
52+
rubocop-ast (1.44.1)
53+
parser (>= 3.3.7.2)
54+
prism (~> 1.4)
55+
rubocop-capybara (2.22.1)
56+
lint_roller (~> 1.1)
57+
rubocop (~> 1.72, >= 1.72.1)
58+
rubocop-discourse (3.12.1)
59+
activesupport (>= 6.1)
60+
lint_roller (>= 1.1.0)
61+
rubocop (>= 1.73.2)
62+
rubocop-capybara (>= 2.22.0)
63+
rubocop-factory_bot (>= 2.27.0)
64+
rubocop-rails (>= 2.30.3)
65+
rubocop-rspec (>= 3.0.1)
66+
rubocop-rspec_rails (>= 2.31.0)
67+
rubocop-factory_bot (2.27.1)
68+
lint_roller (~> 1.1)
69+
rubocop (~> 1.72, >= 1.72.1)
70+
rubocop-rails (2.31.0)
71+
activesupport (>= 4.2.0)
72+
lint_roller (~> 1.1)
73+
rack (>= 1.1)
74+
rubocop (>= 1.75.0, < 2.0)
75+
rubocop-ast (>= 1.38.0, < 2.0)
76+
rubocop-rspec (3.6.0)
77+
lint_roller (~> 1.1)
78+
rubocop (~> 1.72, >= 1.72.1)
79+
rubocop-rspec_rails (2.31.0)
80+
lint_roller (~> 1.1)
81+
rubocop (~> 1.72, >= 1.72.1)
82+
rubocop-rspec (~> 3.5)
83+
ruby-progressbar (1.13.0)
84+
securerandom (0.4.1)
85+
syntax_tree (6.2.0)
86+
prettier_print (>= 1.2.0)
87+
tzinfo (2.0.6)
88+
concurrent-ruby (~> 1.0)
89+
unicode-display_width (3.1.4)
90+
unicode-emoji (~> 4.0, >= 4.0.4)
91+
unicode-emoji (4.0.4)
92+
uri (1.0.3)
93+
94+
PLATFORMS
95+
arm64-darwin-24
96+
ruby
97+
98+
DEPENDENCIES
99+
rubocop-discourse
100+
syntax_tree
101+
102+
BUNDLED WITH
103+
2.6.8

assets/javascripts/discourse/initializers/just-chat.js.es6 renamed to assets/javascripts/discourse/initializers/just-chat.js

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { withPluginApi } from "discourse/lib/plugin-api";
2-
import { getOwner } from "@ember/application";
32

43
export default {
54
name: "just-chat-home-logo-href",
@@ -22,7 +21,7 @@ export default {
2221
} else if (this._super) {
2322
return this._super(...arguments);
2423
}
25-
}
24+
},
2625
});
2726

2827
function redirectToChatAndSidebar(router) {
@@ -35,14 +34,14 @@ export default {
3534
api.modifyClass("route:user-activity-drafts", {
3635
beforeModel() {
3736
redirectToChatAndSidebar(this.router);
38-
}
37+
},
3938
});
4039

4140
// Block user activity route in Ember
4241
api.modifyClass("route:user-activity", {
4342
beforeModel() {
4443
redirectToChatAndSidebar(this.router);
45-
}
44+
},
4645
});
4746

4847
// Force chat sidebar on preferences/account route
@@ -77,14 +76,7 @@ export default {
7776
});
7877

7978
// Redirect all common list/user activity routes to /chat
80-
[
81-
"latest",
82-
"new",
83-
"top",
84-
"hot",
85-
"unread",
86-
"unseen",
87-
].forEach((filter) => {
79+
["latest", "new", "top", "hot", "unread", "unseen"].forEach((filter) => {
8880
api.modifyClass(`route:discovery/${filter}`, {
8981
beforeModel(transition) {
9082
if (
@@ -96,39 +88,49 @@ export default {
9688
} else if (this._super) {
9789
return this._super(...arguments);
9890
}
99-
}
91+
},
10092
});
10193
});
10294

10395
// Intercept category link clicks
10496
api.onPageChange(() => {
10597
// Handle category list links
106-
document.querySelectorAll('.category-title-link').forEach(link => {
107-
link.addEventListener('click', (e) => {
98+
document.querySelectorAll(".category-title-link").forEach((link) => {
99+
link.addEventListener("click", (e) => {
108100
e.preventDefault();
109-
const href = link.getAttribute('href');
101+
const href = link.getAttribute("href");
110102
if (href) {
111103
const router = api.container.lookup("service:router");
112104
// Extract the category path from the href, ignoring IDs
113105
const match = href.match(/\/c\/([^\/]+(?:\/[^\/]+)?)(?:\/\d+)?$/);
114106
if (match) {
115107
// Remove any trailing ID from the category path
116-
const categoryPath = match[1].replace(/\/\d+$/, '');
108+
const categoryPath = match[1].replace(/\/\d+$/, "");
117109
// Check if it's a subcategory
118-
const parts = categoryPath.split('/');
110+
const parts = categoryPath.split("/");
119111
if (parts.length > 1) {
120112
// It's a subcategory, use original parent category
121113
const targetUrl = `/c/${parts[0]}/${parts[1]}/edit/`;
122-
const sidebarState = api.container.lookup("service:sidebar-state");
123-
if (sidebarState && typeof sidebarState.setPanel === "function") {
114+
const sidebarState = api.container.lookup(
115+
"service:sidebar-state"
116+
);
117+
if (
118+
sidebarState &&
119+
typeof sidebarState.setPanel === "function"
120+
) {
124121
sidebarState.setPanel("chat");
125122
}
126123
router.replaceWith(targetUrl);
127124
} else {
128125
// It's a parent category
129126
const targetUrl = `/c/${categoryPath}/edit/`;
130-
const sidebarState = api.container.lookup("service:sidebar-state");
131-
if (sidebarState && typeof sidebarState.setPanel === "function") {
127+
const sidebarState = api.container.lookup(
128+
"service:sidebar-state"
129+
);
130+
if (
131+
sidebarState &&
132+
typeof sidebarState.setPanel === "function"
133+
) {
132134
sidebarState.setPanel("chat");
133135
}
134136
router.replaceWith(targetUrl);
@@ -139,41 +141,55 @@ export default {
139141
});
140142

141143
// Handle chat interface category links
142-
document.querySelectorAll('.badge-category__wrapper').forEach(link => {
143-
link.addEventListener('click', (e) => {
144-
e.preventDefault();
145-
const href = link.getAttribute('href');
146-
if (href) {
147-
const router = api.container.lookup("service:router");
148-
// Extract the category path from the href, ignoring IDs
149-
const match = href.match(/\/c\/([^\/]+(?:\/[^\/]+)?)(?:\/\d+)?$/);
150-
if (match) {
151-
// Remove any trailing ID from the category path
152-
const categoryPath = match[1].replace(/\/\d+$/, '');
153-
// Check if it's a subcategory
154-
const parts = categoryPath.split('/');
155-
if (parts.length > 1) {
156-
// It's a subcategory, use original parent category
157-
const targetUrl = `/c/${parts[0]}/${parts[1]}/edit/`;
158-
const sidebarState = api.container.lookup("service:sidebar-state");
159-
if (sidebarState && typeof sidebarState.setPanel === "function") {
160-
sidebarState.setPanel("chat");
161-
}
162-
router.replaceWith(targetUrl);
163-
} else {
164-
// It's a parent category
165-
const targetUrl = `/c/${categoryPath}/edit/`;
166-
const sidebarState = api.container.lookup("service:sidebar-state");
167-
if (sidebarState && typeof sidebarState.setPanel === "function") {
168-
sidebarState.setPanel("chat");
144+
document
145+
.querySelectorAll(".badge-category__wrapper")
146+
.forEach((link) => {
147+
link.addEventListener("click", (e) => {
148+
e.preventDefault();
149+
const href = link.getAttribute("href");
150+
if (href) {
151+
const router = api.container.lookup("service:router");
152+
// Extract the category path from the href, ignoring IDs
153+
const match = href.match(
154+
/\/c\/([^\/]+(?:\/[^\/]+)?)(?:\/\d+)?$/
155+
);
156+
if (match) {
157+
// Remove any trailing ID from the category path
158+
const categoryPath = match[1].replace(/\/\d+$/, "");
159+
// Check if it's a subcategory
160+
const parts = categoryPath.split("/");
161+
if (parts.length > 1) {
162+
// It's a subcategory, use original parent category
163+
const targetUrl = `/c/${parts[0]}/${parts[1]}/edit/`;
164+
const sidebarState = api.container.lookup(
165+
"service:sidebar-state"
166+
);
167+
if (
168+
sidebarState &&
169+
typeof sidebarState.setPanel === "function"
170+
) {
171+
sidebarState.setPanel("chat");
172+
}
173+
router.replaceWith(targetUrl);
174+
} else {
175+
// It's a parent category
176+
const targetUrl = `/c/${categoryPath}/edit/`;
177+
const sidebarState = api.container.lookup(
178+
"service:sidebar-state"
179+
);
180+
if (
181+
sidebarState &&
182+
typeof sidebarState.setPanel === "function"
183+
) {
184+
sidebarState.setPanel("chat");
185+
}
186+
router.replaceWith(targetUrl);
169187
}
170-
router.replaceWith(targetUrl);
171188
}
172189
}
173-
}
190+
});
174191
});
175-
});
176192
});
177193
});
178-
}
194+
},
179195
};

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
Discourse::Application.routes.draw do
99
mount ::JustChatModule::Engine, at: "discourse-just-chat"
1010
# Redirect root to /chat for all users
11-
root to: redirect('/chat')
11+
root to: redirect("/chat")
1212
end

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import DiscourseRecommended from "@discourse/lint-configs/eslint";
2+
3+
export default [...DiscourseRecommended];

0 commit comments

Comments
 (0)