DEV: apply coding standards (#43)

This commit is contained in:
Joffrey JAFFEUX 2020-09-04 13:23:28 +02:00 committed by GitHub
parent ebb190d5e6
commit 9327e705cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 1227 additions and 735 deletions

104
.eslintrc
View File

@ -1,105 +1,3 @@
{
"env": {
"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,
"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,
"selectKit":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"
"extends": "eslint-config-discourse"
}

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ auto_generated/
node_modules/
.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
node_modules
yarn-error.log
.rubocop-https---raw-githubusercontent-com-discourse-*

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

@ -2,8 +2,8 @@ export default {
resource: "admin.adminPlugins",
path: "/plugins",
map() {
this.route("chat", function() {
this.route("chat", function () {
this.route("provider", { path: "/:provider" });
});
}
},
};

View File

@ -1,3 +1,3 @@
export default Ember.Component.extend({
classNames: ["channel-info"]
classNames: ["channel-info"],
});

View File

@ -1,4 +1,5 @@
import { popupAjaxError } from "discourse/lib/ajax-error";
import I18n from "I18n";
export default Ember.Component.extend({
classNames: ["channel-details"],
@ -9,7 +10,7 @@ export default Ember.Component.extend({
I18n.t("chat_integration.channel_delete_confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
result => {
(result) => {
if (result) {
channel
.destroyRecord()
@ -22,6 +23,6 @@ export default Ember.Component.extend({
editRule(rule) {
this.editRuleWithChannel(rule, this.get("channel"));
}
}
},
},
});

View File

@ -25,6 +25,6 @@ export default Ember.Component.extend({
.destroyRecord()
.then(() => this.refresh())
.catch(popupAjaxError);
}
}
},
},
});

View File

@ -8,7 +8,7 @@ export default Ember.Controller.extend({
anyErrors(channels) {
let anyErrors = false;
channels.forEach(channel => {
channels.forEach((channel) => {
if (channel.error_key) {
anyErrors = true;
}
@ -24,14 +24,14 @@ export default Ember.Controller.extend({
const model = {
channel: this.store.createRecord("channel", {
provider: this.get("model.provider.id"),
data: {}
data: {},
}),
provider: this.get("model.provider")
provider: this.get("model.provider"),
};
showModal("admin-plugins-chat-edit-channel", {
model,
admin: true
admin: true,
});
},
@ -40,12 +40,12 @@ export default Ember.Controller.extend({
const model = {
channel,
provider: this.get("model.provider")
provider: this.get("model.provider"),
};
showModal("admin-plugins-chat-edit-channel", {
model,
admin: true
admin: true,
});
},
@ -53,7 +53,7 @@ export default Ember.Controller.extend({
this.set("modalShowing", true);
showModal("admin-plugins-chat-test", {
model: { channel },
admin: true
admin: true,
});
},
@ -63,11 +63,11 @@ export default Ember.Controller.extend({
const model = {
rule: this.store.createRecord("rule", {
channel_id: channel.id,
channel
channel,
}),
channel,
provider: this.get("model.provider"),
groups: this.get("model.groups")
groups: this.get("model.groups"),
};
showModal("admin-plugins-chat-edit-rule", { model, admin: true });
@ -80,7 +80,7 @@ export default Ember.Controller.extend({
rule,
channel,
provider: this.get("model.provider"),
groups: this.get("model.groups")
groups: this.get("model.groups"),
};
showModal("admin-plugins-chat-edit-rule", { model, admin: true });
@ -91,8 +91,8 @@ export default Ember.Controller.extend({
showModal("admin-plugins-chat-channel-error", {
model: channel,
admin: true
admin: true,
});
}
}
},
},
});

View File

@ -1,17 +1,18 @@
import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { popupAjaxError } from "discourse/lib/ajax-error";
import InputValidation from "discourse/models/input-validation";
import {
default as computed,
observes,
on
on,
} from "discourse-common/utils/decorators";
export default Ember.Controller.extend(ModalFunctionality, {
@on("init")
setupKeydown() {
Ember.run.schedule("afterRender", () => {
$("#chat-integration-edit-channel-modal").keydown(e => {
$("#chat-integration-edit-channel-modal").keydown((e) => {
if (e.keyCode === 13) {
this.send("save");
}
@ -24,7 +25,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
setupValidations() {
if (this.get("model.provider")) {
const theKeys = this.get("model.provider.channel_parameters").map(
param => param["key"]
(param) => param["key"]
);
Ember.defineProperty(
this,
@ -49,12 +50,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
if (val === "") {
// Fail silently if field blank
return InputValidation.create({
failed: true
failed: true,
});
} else if (!regString) {
// Pass silently if no regex available for provider
return InputValidation.create({
ok: true
ok: true,
});
} else if (regex.test(val)) {
// Test against regex
@ -62,7 +63,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
ok: true,
reason: I18n.t(
"chat_integration.edit_channel_modal.channel_validation.ok"
)
),
});
} else {
// Failed regex
@ -70,7 +71,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
failed: true,
reason: I18n.t(
"chat_integration.edit_channel_modal.channel_validation.fail"
)
),
});
}
},
@ -79,7 +80,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
const response = {};
const parameters = this.get("model.provider.channel_parameters");
parameters.forEach(parameter => {
parameters.forEach((parameter) => {
response[parameter.key] = this.validate(parameter);
});
@ -92,7 +93,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
let invalid = false;
Object.keys(paramValidation).forEach(key => {
Object.keys(paramValidation).forEach((key) => {
if (!paramValidation[key]) {
invalid = true;
}
@ -119,6 +120,6 @@ export default Ember.Controller.extend(ModalFunctionality, {
this.send("closeModal");
})
.catch(popupAjaxError);
}
}
},
},
});

View File

@ -8,7 +8,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
@on("init")
setupKeydown() {
Ember.run.schedule("afterRender", () => {
$("#chat-integration-edit-channel-modal").keydown(e => {
$("#chat-integration-edit-channel-modal").keydown((e) => {
if (e.keyCode === 13) {
this.send("save");
}
@ -29,6 +29,6 @@ export default Ember.Controller.extend(ModalFunctionality, {
.save()
.then(() => this.send("closeModal"))
.catch(popupAjaxError);
}
}
},
},
});

View File

@ -1,3 +1,4 @@
import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
@ -7,7 +8,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
@on("init")
setupKeydown() {
Ember.run.schedule("afterRender", () => {
$("#chat_integration_test_modal").keydown(e => {
$("#chat_integration_test_modal").keydown((e) => {
if (e.keyCode === 13) {
this.send("send");
}
@ -28,15 +29,15 @@ export default Ember.Controller.extend(ModalFunctionality, {
ajax("/admin/plugins/chat/test", {
data: {
channel_id: this.get("model.channel.id"),
topic_id: this.get("model.topic_id")
topic_id: this.get("model.topic_id"),
},
type: "POST"
type: "POST",
})
.then(() => {
this.set("loading", false);
this.flash(I18n.t("chat_integration.test_modal.success"), "success");
})
.catch(popupAjaxError);
}
}
},
},
});

View File

@ -7,5 +7,5 @@ export default RestModel.extend({
createProperties() {
return this.getProperties(["provider", "data"]);
}
},
});

View File

@ -1,8 +1,9 @@
import I18n from "I18n";
import RestModel from "discourse/models/rest";
import Category from "discourse/models/category";
import {
default as computed,
observes
observes,
} from "discourse-common/utils/decorators";
export default RestModel.extend({
@ -14,7 +15,7 @@ export default RestModel.extend({
available.push({
id: "thread",
name: I18n.t("chat_integration.filter.thread"),
icon: "chevron-right"
icon: "chevron-right",
});
}
@ -22,17 +23,17 @@ export default RestModel.extend({
{
id: "watch",
name: I18n.t("chat_integration.filter.watch"),
icon: "exclamation-circle"
icon: "exclamation-circle",
},
{
id: "follow",
name: I18n.t("chat_integration.filter.follow"),
icon: "circle"
icon: "circle",
},
{
id: "mute",
name: I18n.t("chat_integration.filter.mute"),
icon: "times-circle"
icon: "times-circle",
}
);
@ -43,9 +44,12 @@ export default RestModel.extend({
{ id: "normal", name: I18n.t("chat_integration.type.normal") },
{
id: "group_message",
name: I18n.t("chat_integration.type.group_message")
name: I18n.t("chat_integration.type.group_message"),
},
{
id: "group_mention",
name: I18n.t("chat_integration.type.group_mention"),
},
{ id: "group_mention", name: I18n.t("chat_integration.type.group_mention") }
],
category_id: null,
@ -86,7 +90,7 @@ export default RestModel.extend({
"category_id",
"group_id",
"tags",
"filter"
"filter",
]);
},
@ -97,7 +101,7 @@ export default RestModel.extend({
"category_id",
"group_id",
"tags",
"filter"
"filter",
]);
}
},
});

View File

@ -8,5 +8,5 @@ export default DiscourseRoute.extend({
model.get("firstObject").name
);
}
}
},
});

View File

@ -9,14 +9,14 @@ export default DiscourseRoute.extend({
"id",
params.provider
),
groups: Group.findAll().then(groups => {
return groups.filter(g => !g.get("automatic"));
})
}).then(value => {
value.channels.forEach(channel => {
groups: Group.findAll().then((groups) => {
return groups.filter((g) => !g.get("automatic"));
}),
}).then((value) => {
value.channels.forEach((channel) => {
channel.set(
"rules",
channel.rules.map(rule => {
channel.rules.map((rule) => {
rule = this.store.createRecord("rule", rule);
rule.set("channel", channel);
return rule;
@ -44,6 +44,6 @@ export default DiscourseRoute.extend({
refreshProvider() {
this.refresh();
}
}
},
},
});

View File

@ -8,8 +8,8 @@ export default DiscourseRoute.extend({
actions: {
showSettings() {
this.transitionTo("adminSiteSettingsCategory", "plugins", {
queryParams: { filter: "chat_integration" }
queryParams: { filter: "chat_integration" },
});
}
}
},
},
});

View File

@ -1,3 +1,3 @@
export default function() {
export default function () {
this.route("transcript", { path: "/chat-transcript/:secret" });
}

View File

@ -7,10 +7,10 @@ export default DiscourseRoute.extend({
if (this.currentUser) {
const secret = params.secret;
this.replaceWith("discovery.latest").then(e => {
this.replaceWith("discovery.latest").then((e) => {
if (this.controllerFor("navigation/default").get("canCreateTopic")) {
Ember.run.next(() => {
ajax(`chat-transcript/${secret}`).then(result => {
ajax(`chat-transcript/${secret}`).then((result) => {
e.send(
"createNewTopicViaParams",
null,
@ -27,5 +27,5 @@ export default DiscourseRoute.extend({
this.session.set("shouldRedirectToUrl", window.location.href);
this.replaceWith("login");
}
}
},
});

View File

@ -5,8 +5,6 @@
"author": "Discourse",
"license": "MIT",
"devDependencies": {
"babel-eslint": "^8.2",
"eslint": "^4.19",
"prettier": "1.14.3"
"eslint-config-discourse": "latest"
}
}

View File

@ -3,15 +3,15 @@ acceptance("Chat Integration", {
loggedIn: true,
pretend(server) {
const response = object => {
const response = (object) => {
return [200, { "Content-Type": "text/html; charset=utf-8" }, object];
};
const jsonResponse = object => {
const jsonResponse = (object) => {
return [
200,
{ "Content-Type": "application/json; charset=utf-8" },
object
object,
];
};
@ -21,9 +21,9 @@ acceptance("Chat Integration", {
{
name: "dummy",
id: "dummy",
channel_parameters: [{ key: "somekey", regex: "^\\S+$" }]
}
]
channel_parameters: [{ key: "somekey", regex: "^\\S+$" }],
},
],
});
});
@ -43,11 +43,11 @@ acceptance("Chat Integration", {
type: "normal",
tags: [],
filter: "watch",
error_key: null
}
]
}
]
error_key: null,
},
],
},
],
});
});
@ -82,25 +82,22 @@ acceptance("Chat Integration", {
server.get("/groups/search.json", () => {
return jsonResponse([]);
});
}
},
});
test("Rules load successfully", async assert => {
test("Rules load successfully", async (assert) => {
await visit("/admin/plugins/chat");
assert.ok(exists("#admin-plugin-chat table"), "it shows the table of rules");
assert.equal(
find("#admin-plugin-chat table tr td")
.eq(0)
.text()
.trim(),
find("#admin-plugin-chat table tr td").eq(0).text().trim(),
"All posts and replies",
"rule displayed"
);
});
test("Create channel works", async assert => {
test("Create channel works", async (assert) => {
await visit("/admin/plugins/chat");
await click("#create-channel");
@ -128,7 +125,7 @@ test("Create channel works", async assert => {
);
});
test("Edit channel works", async assert => {
test("Edit channel works", async (assert) => {
await visit("/admin/plugins/chat");
await click(".channel-header button:first");
@ -161,7 +158,7 @@ test("Edit channel works", async assert => {
});
});
test("Create rule works", async assert => {
test("Create rule works", async (assert) => {
await visit("/admin/plugins/chat");
assert.ok(
@ -182,7 +179,7 @@ test("Create rule works", async assert => {
);
});
test("Edit rule works", async assert => {
test("Edit rule works", async (assert) => {
await visit("/admin/plugins/chat");
assert.ok(exists(".edit:first"), "edit button is displayed");
@ -203,7 +200,7 @@ test("Edit rule works", async assert => {
);
});
test("Delete channel works", async assert => {
test("Delete channel works", async (assert) => {
await visit("/admin/plugins/chat");
assert.ok(exists(".channel-header button:last"), "delete button exists");
@ -215,14 +212,14 @@ test("Delete channel works", async assert => {
assert.ok(exists("div.bootbox") === false, "modal has closed");
});
test("Delete rule works", async assert => {
test("Delete rule works", async (assert) => {
await visit("/admin/plugins/chat");
assert.ok(exists(".delete:first"));
await click(".delete:first");
});
test("Test channel works", async assert => {
test("Test channel works", async (assert) => {
await visit("/admin/plugins/chat");
await click(".btn-chat-test");

1661
yarn.lock

File diff suppressed because it is too large Load Diff