DEV: apply coding standards (#90)

This commit is contained in:
Joffrey JAFFEUX 2020-09-04 13:22:22 +02:00 committed by GitHub
parent c89e0dda19
commit 613267c3a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1675 additions and 166 deletions

105
.eslintrc
View File

@ -1,106 +1,3 @@
{ {
"env": { "extends": "eslint-config-discourse"
"jasmine": true,
"node": true,
"mocha": true,
"browser": true,
"builtin": true
},
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"globals":
{"Ember":true,
"jQuery":true,
"$":true,
"RSVP":true,
"Discourse":true,
"Em":true,
"PreloadStore":true,
"Handlebars":true,
"I18n":true,
"bootbox":true,
"module":true,
"moduleFor":true,
"moduleForComponent":true,
"Pretender":true,
"sandbox":true,
"controllerFor":true,
"test":true,
"ok":true,
"not":true,
"expect":true,
"equal":true,
"visit":true,
"andThen":true,
"click":true,
"currentPath":true,
"currentRouteName":true,
"currentURL":true,
"fillIn":true,
"keyEvent":true,
"triggerEvent":true,
"count":true,
"exists":true,
"visible":true,
"invisible":true,
"asyncRender":true,
"selectDropdown":true,
"asyncTestDiscourse":true,
"fixture":true,
"find":true,
"sinon":true,
"moment":true,
"start":true,
"_":true,
"alert":true,
"containsInstance":true,
"deepEqual":true,
"notEqual":true,
"define":true,
"require":true,
"requirejs":true,
"hasModule":true,
"Blob":true,
"File":true},
"rules": {
"block-scoped-var": 2,
"dot-notation": 0,
"eqeqeq": [
2,
"allow-null"
],
"guard-for-in": 2,
"no-bitwise": 2,
"no-caller": 2,
"no-cond-assign": 0,
"no-debugger": 2,
"no-empty": 0,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 0,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-loop-func": 2,
"no-multi-str": 2,
"no-new": 2,
"no-plusplus": 0,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-undef": 2,
"no-unused-vars": 2,
"no-with": 2,
"no-this-before-super": 2,
"semi": 2,
"strict": 0,
"valid-typeof": 2,
"wrap-iife": [
2,
"inside"
]
},
"parser": "babel-eslint"
} }

3
.gitignore vendored
View File

@ -0,0 +1,3 @@
node_modules
yarn-error.log
.rubocop-https---raw-githubusercontent-com-discourse-*

1
.prettierrc Normal file
View File

@ -0,0 +1 @@
{}

4
.template-lintrc.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
plugins: ["ember-template-lint-plugin-discourse"],
extends: "discourse:recommended",
};

View File

@ -1,3 +1,4 @@
import I18n from "I18n";
import DiscourseUrl from "discourse/lib/url"; import DiscourseUrl from "discourse/lib/url";
export default { export default {
@ -16,10 +17,10 @@ export default {
}, },
setupComponent(args, component) { setupComponent(args, component) {
const statuses = ["all", "solved", "unsolved"].map(status => { const statuses = ["all", "solved", "unsolved"].map((status) => {
return { return {
name: I18n.t(`solved.topic_status_filter.${status}`), name: I18n.t(`solved.topic_status_filter.${status}`),
value: status value: status,
}; };
}); });
component.set("statuses", statuses); component.set("statuses", statuses);
@ -42,7 +43,7 @@ export default {
? queryStrings.substr(1).split("&") ? queryStrings.substr(1).split("&")
: []; : [];
params = params.filter(param => !param.startsWith("solved=")); params = params.filter((param) => !param.startsWith("solved="));
if (newStatus && newStatus !== "all") { if (newStatus && newStatus !== "all") {
newStatus = newStatus === "solved" ? "yes" : "no"; newStatus = newStatus === "solved" ? "yes" : "no";
@ -53,6 +54,6 @@ export default {
DiscourseUrl.routeTo( DiscourseUrl.routeTo(
`${location.pathname}${queryStrings}${location.hash}` `${location.pathname}${queryStrings}${location.hash}`
); );
} },
} },
}; };

View File

@ -5,6 +5,6 @@ export default {
"category.custom_fields.enable_accepted_answers", "category.custom_fields.enable_accepted_answers",
value ? "true" : "false" value ? "true" : "false"
); );
} },
} },
}; };

View File

@ -1,3 +1,4 @@
import I18n from "I18n";
import Topic from "discourse/models/topic"; import Topic from "discourse/models/topic";
import User from "discourse/models/user"; import User from "discourse/models/user";
import TopicStatus from "discourse/raw-views/topic-status"; import TopicStatus from "discourse/raw-views/topic-status";
@ -13,12 +14,12 @@ import SearchAdvancedOptions from "discourse/components/search-advanced-options"
function clearAccepted(topic) { function clearAccepted(topic) {
const posts = topic.get("postStream.posts"); const posts = topic.get("postStream.posts");
posts.forEach(post => { posts.forEach((post) => {
if (post.get("post_number") > 1) { if (post.get("post_number") > 1) {
post.setProperties({ post.setProperties({
accepted_answer: false, accepted_answer: false,
can_accept_answer: true, can_accept_answer: true,
can_unaccept_answer: false can_unaccept_answer: false,
}); });
} }
}); });
@ -33,13 +34,13 @@ function unacceptPost(post) {
post.setProperties({ post.setProperties({
can_accept_answer: true, can_accept_answer: true,
can_unaccept_answer: false, can_unaccept_answer: false,
accepted_answer: false accepted_answer: false,
}); });
topic.set("accepted_answer", undefined); topic.set("accepted_answer", undefined);
ajax("/solution/unaccept", { ajax("/solution/unaccept", {
type: "POST", type: "POST",
data: { id: post.id } data: { id: post.id },
}).catch(popupAjaxError); }).catch(popupAjaxError);
} }
@ -51,18 +52,18 @@ function acceptPost(post) {
post.setProperties({ post.setProperties({
can_unaccept_answer: true, can_unaccept_answer: true,
can_accept_answer: false, can_accept_answer: false,
accepted_answer: true accepted_answer: true,
}); });
topic.set("accepted_answer", { topic.set("accepted_answer", {
username: post.username, username: post.username,
post_number: post.post_number, post_number: post.post_number,
excerpt: post.cooked excerpt: post.cooked,
}); });
ajax("/solution/accept", { ajax("/solution/accept", {
type: "POST", type: "POST",
data: { id: post.id } data: { id: post.id },
}).catch(popupAjaxError); }).catch(popupAjaxError);
} }
@ -72,7 +73,7 @@ function initializeWithApi(api) {
TopicStatusIcons.addObject([ TopicStatusIcons.addObject([
"has_accepted_answer", "has_accepted_answer",
"far-check-square", "far-check-square",
"solved" "solved",
]); ]);
api.includePostAttributes( api.includePostAttributes(
@ -85,7 +86,7 @@ function initializeWithApi(api) {
api.addDiscoveryQueryParam("solved", { replace: true, refreshModel: true }); api.addDiscoveryQueryParam("solved", { replace: true, refreshModel: true });
} }
api.addPostMenuButton("solved", attrs => { api.addPostMenuButton("solved", (attrs) => {
const canAccept = attrs.can_accept_answer; const canAccept = attrs.can_accept_answer;
const canUnaccept = attrs.can_unaccept_answer; const canUnaccept = attrs.can_unaccept_answer;
const accepted = attrs.accepted_answer; const accepted = attrs.accepted_answer;
@ -100,7 +101,7 @@ function initializeWithApi(api) {
className: "unaccepted", className: "unaccepted",
title: "solved.accept_answer", title: "solved.accept_answer",
label: "solved.solution", label: "solved.solution",
position position,
}; };
} else if (canUnaccept && accepted) { } else if (canUnaccept && accepted) {
const title = canUnaccept const title = canUnaccept
@ -112,7 +113,7 @@ function initializeWithApi(api) {
title, title,
className: "accepted fade-out", className: "accepted fade-out",
position, position,
label: "solved.solution" label: "solved.solution",
}; };
} else if (!canAccept && accepted) { } else if (!canAccept && accepted) {
return { return {
@ -123,19 +124,19 @@ function initializeWithApi(api) {
return h( return h(
"span.accepted-text", "span.accepted-text",
{ {
title: I18n.t("solved.accepted_description") title: I18n.t("solved.accepted_description"),
}, },
[ [
h("span", iconNode("check")), h("span", iconNode("check")),
h("span.accepted-label", I18n.t("solved.solution")) h("span.accepted-label", I18n.t("solved.solution")),
] ]
); );
} },
}; };
} }
}); });
api.decorateWidget("post-contents:after-cooked", dec => { api.decorateWidget("post-contents:after-cooked", (dec) => {
if (dec.attrs.post_number === 1) { if (dec.attrs.post_number === 1) {
const postModel = dec.getModel(); const postModel = dec.getModel();
if (postModel) { if (postModel) {
@ -174,12 +175,12 @@ function initializeWithApi(api) {
api.attachWidgetAction("post", "acceptAnswer", function () { api.attachWidgetAction("post", "acceptAnswer", function () {
const post = this.model; const post = this.model;
const current = post.get("topic.postStream.posts").filter(p => { const current = post.get("topic.postStream.posts").filter((p) => {
return p.post_number === 1 || p.accepted_answer; return p.post_number === 1 || p.accepted_answer;
}); });
acceptPost(post); acceptPost(post);
current.forEach(p => current.forEach((p) =>
this.appEvents.trigger("post-stream:refresh", { id: p.id }) this.appEvents.trigger("post-stream:refresh", { id: p.id })
); );
}); });
@ -188,7 +189,7 @@ function initializeWithApi(api) {
const post = this.model; const post = this.model;
const op = post const op = post
.get("topic.postStream.posts") .get("topic.postStream.posts")
.find(p => p.post_number === 1); .find((p) => p.post_number === 1);
unacceptPost(post); unacceptPost(post);
this.appEvents.trigger("post-stream:refresh", { id: op.id }); this.appEvents.trigger("post-stream:refresh", { id: op.id });
}); });
@ -197,7 +198,7 @@ function initializeWithApi(api) {
api.registerConnectorClass("user-activity-bottom", "solved-list", { api.registerConnectorClass("user-activity-bottom", "solved-list", {
shouldRender(args, component) { shouldRender(args, component) {
return component.siteSettings.solved_enabled; return component.siteSettings.solved_enabled;
} },
}); });
api.registerConnectorClass("user-summary-stat", "solved-count", { api.registerConnectorClass("user-summary-stat", "solved-count", {
shouldRender(args, component) { shouldRender(args, component) {
@ -207,7 +208,7 @@ function initializeWithApi(api) {
}, },
setupComponent() { setupComponent() {
this.set("classNames", ["linked-stat"]); this.set("classNames", ["linked-stat"]);
} },
}); });
} }
} }
@ -231,9 +232,9 @@ export default {
username: formatUsername(username), username: formatUsername(username),
post_path: `${this.url}/${postNumber}`, post_path: `${this.url}/${postNumber}`,
post_number: postNumber, post_number: postNumber,
user_path: User.create({ username }).path user_path: User.create({ username }).path,
}); });
}) }),
}); });
TopicStatus.reopen({ TopicStatus.reopen({
@ -245,7 +246,7 @@ export default {
openTag: "span", openTag: "span",
closeTag: "span", closeTag: "span",
title: I18n.t("topic_statuses.solved.help"), title: I18n.t("topic_statuses.solved.help"),
icon: "far-check-square" icon: "far-check-square",
}); });
} else if ( } else if (
this.topic.can_have_answer && this.topic.can_have_answer &&
@ -256,11 +257,11 @@ export default {
openTag: "span", openTag: "span",
closeTag: "span", closeTag: "span",
title: I18n.t("solved.has_no_accepted_answer"), title: I18n.t("solved.has_no_accepted_answer"),
icon: "far-square" icon: "far-square",
}); });
} }
return results; return results;
}) }),
}); });
SearchAdvancedOptions.reopen({ SearchAdvancedOptions.reopen({
@ -268,18 +269,18 @@ export default {
this._super(); this._super();
this.statusOptions.push({ this.statusOptions.push({
name: I18n.t("search.advanced.statuses.solved"), name: I18n.t("search.advanced.statuses.solved"),
value: "solved" value: "solved",
}); });
} },
}); });
withPluginApi("0.1", initializeWithApi); withPluginApi("0.1", initializeWithApi);
withPluginApi("0.8.10", api => { withPluginApi("0.8.10", (api) => {
api.replaceIcon( api.replaceIcon(
"notification.solved.accepted_notification", "notification.solved.accepted_notification",
"check-square" "check-square"
); );
}); });
} },
}; };

View File

@ -12,9 +12,9 @@ export default {
{ {
get(fieldName) { get(fieldName) {
return Ember.get(this.custom_fields, fieldName) === "true"; return Ember.get(this.custom_fields, fieldName) === "true";
},
} }
} ),
)
}); });
} },
}; };

View File

@ -2,5 +2,5 @@ import UserActivityStreamRoute from "discourse/routes/user-activity-stream";
export default UserActivityStreamRoute.extend({ export default UserActivityStreamRoute.extend({
userActionType: 15, userActionType: 15,
noContentHelpKey: "solved.no_solutions" noContentHelpKey: "solved.no_solutions",
}); });

View File

@ -3,5 +3,5 @@ export default {
map() { map() {
this.route("solved"); this.route("solved");
} },
}; };

7
package.json Normal file
View File

@ -0,0 +1,7 @@
{
"author": "Discourse",
"license": "MIT",
"devDependencies": {
"eslint-config-discourse": "latest"
}
}

View File

@ -3,11 +3,11 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Discourse Solved Plugin", { acceptance("Discourse Solved Plugin", {
loggedIn: true, loggedIn: true,
beforeEach() { beforeEach() {
const response = object => { const response = (object) => {
return [200, { "Content-Type": "application/json" }, object]; return [200, { "Content-Type": "application/json" }, object];
}; };
const postStreamWithAcceptedAnswerExcerpt = excerpt => { const postStreamWithAcceptedAnswerExcerpt = (excerpt) => {
return { return {
post_stream: { post_stream: {
posts: [ posts: [
@ -49,7 +49,7 @@ acceptance("Discourse Solved Plugin", {
{ id: 4, can_act: true }, { id: 4, can_act: true },
{ id: 5, hidden: true, can_act: true }, { id: 5, hidden: true, can_act: true },
{ id: 7, can_act: true }, { id: 7, can_act: true },
{ id: 8, can_act: true } { id: 8, can_act: true },
], ],
moderator: false, moderator: false,
admin: true, admin: true,
@ -65,7 +65,7 @@ acceptance("Discourse Solved Plugin", {
wiki: false, wiki: false,
can_accept_answer: false, can_accept_answer: false,
can_unaccept_answer: false, can_unaccept_answer: false,
accepted_answer: false accepted_answer: false,
}, },
{ {
id: 22, id: 22,
@ -106,7 +106,7 @@ acceptance("Discourse Solved Plugin", {
{ id: 4, can_act: true }, { id: 4, can_act: true },
{ id: 5, hidden: true, can_act: true }, { id: 5, hidden: true, can_act: true },
{ id: 7, can_act: true }, { id: 7, can_act: true },
{ id: 8, can_act: true } { id: 8, can_act: true },
], ],
moderator: false, moderator: false,
admin: true, admin: true,
@ -122,10 +122,10 @@ acceptance("Discourse Solved Plugin", {
wiki: false, wiki: false,
can_accept_answer: false, can_accept_answer: false,
can_unaccept_answer: true, can_unaccept_answer: true,
accepted_answer: true accepted_answer: true,
} },
], ],
stream: [21, 22] stream: [21, 22],
}, },
timeline_lookup: [[1, 0]], timeline_lookup: [[1, 0]],
id: 23, id: 23,
@ -164,13 +164,13 @@ acceptance("Discourse Solved Plugin", {
id: 1, id: 1,
username: "kzh", username: "kzh",
avatar_template: avatar_template:
"/letter_avatar_proxy/v2/letter/k/ac91a4/{size}.png" "/letter_avatar_proxy/v2/letter/k/ac91a4/{size}.png",
}, },
last_poster: { last_poster: {
id: 1, id: 1,
username: "kzh", username: "kzh",
avatar_template: avatar_template:
"/letter_avatar_proxy/v2/letter/k/ac91a4/{size}.png" "/letter_avatar_proxy/v2/letter/k/ac91a4/{size}.png",
}, },
participants: [ participants: [
{ {
@ -182,8 +182,8 @@ acceptance("Discourse Solved Plugin", {
primary_group_name: null, primary_group_name: null,
primary_group_flair_url: null, primary_group_flair_url: null,
primary_group_flair_color: null, primary_group_flair_color: null,
primary_group_flair_bg_color: null primary_group_flair_bg_color: null,
} },
], ],
notification_level: 3, notification_level: 3,
notifications_reason_id: 1, notifications_reason_id: 1,
@ -195,7 +195,7 @@ acceptance("Discourse Solved Plugin", {
can_invite_via_email: true, can_invite_via_email: true,
can_create_post: true, can_create_post: true,
can_reply_as_new_topic: true, can_reply_as_new_topic: true,
can_flag_topic: true can_flag_topic: true,
}, },
highest_post_number: 2, highest_post_number: 2,
last_read_post_number: 2, last_read_post_number: 2,
@ -205,7 +205,7 @@ acceptance("Discourse Solved Plugin", {
actions_summary: [ actions_summary: [
{ id: 4, count: 0, hidden: false, can_act: true }, { id: 4, count: 0, hidden: false, can_act: true },
{ id: 7, count: 0, hidden: false, can_act: true }, { id: 7, count: 0, hidden: false, can_act: true },
{ id: 8, count: 0, hidden: false, can_act: true } { id: 8, count: 0, hidden: false, can_act: true },
], ],
chunk_size: 20, chunk_size: 20,
bookmarked: false, bookmarked: false,
@ -213,7 +213,7 @@ acceptance("Discourse Solved Plugin", {
featured_link: null, featured_link: null,
topic_timer: null, topic_timer: null,
message_bus_last_id: 0, message_bus_last_id: 0,
accepted_answer: { post_number: 2, username: "kzh", excerpt: excerpt } accepted_answer: { post_number: 2, username: "kzh", excerpt: excerpt },
}; };
}; };
@ -228,10 +228,10 @@ acceptance("Discourse Solved Plugin", {
server.get("/t/12.json", () => { server.get("/t/12.json", () => {
return response(postStreamWithAcceptedAnswerExcerpt(null)); return response(postStreamWithAcceptedAnswerExcerpt(null));
}); });
} },
}); });
test("A topic with an accepted answer shows an excerpt of the answer, if provided", assert => { test("A topic with an accepted answer shows an excerpt of the answer, if provided", (assert) => {
visit("/t/with-excerpt/11"); visit("/t/with-excerpt/11");
andThen(() => { andThen(() => {

1595
yarn.lock Normal file

File diff suppressed because it is too large Load Diff