DEV: Update linting (#267)

This commit is contained in:
Jarek Radosz 2023-12-01 16:47:54 +01:00 committed by GitHub
parent 840caa3987
commit e067df0b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 1181 additions and 958 deletions

View File

@ -1,3 +0,0 @@
{
"extends": "eslint-config-discourse"
}

1
.eslintrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/eslint");

View File

@ -1 +0,0 @@
{}

1
.prettierrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/prettier");

1
.template-lintrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require("@discourse/lint-configs/template-lint");

View File

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

View File

@ -2,35 +2,45 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.6.2)
parallel (1.22.1)
parser (3.1.2.1)
json (2.6.3)
language_server-protocol (3.17.0.3)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
prettier_print (1.2.0)
racc
prettier_print (1.2.1)
racc (1.7.3)
rainbow (3.1.1)
regexp_parser (2.6.0)
rexml (3.2.5)
rubocop (1.36.0)
regexp_parser (2.8.2)
rexml (3.2.6)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-discourse (3.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-discourse (3.4.1)
rubocop (>= 1.1.0)
rubocop-rspec (>= 2.0.0)
rubocop-rspec (2.13.2)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
syntax_tree (5.1.0)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
unicode-display_width (2.3.0)
unicode-display_width (2.5.0)
PLATFORMS
arm64-darwin-20

View File

@ -10,13 +10,13 @@ module ::DiscourseDataExplorer
validates :name, presence: true
scope :for_group,
->(group) {
->(group) do
where(hidden: false).joins(
"INNER JOIN data_explorer_query_groups
ON data_explorer_query_groups.query_id = data_explorer_queries.id
AND data_explorer_query_groups.group_id = #{group.id}",
)
}
end
def params
@params ||= Parameter.create_from_sql(sql)

View File

@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import loadScript from "discourse/lib/load-script";
import themeColor from "../lib/themeColor";
import { bind } from "discourse-common/utils/decorators";
import { action } from "@ember/object";
import loadScript from "discourse/lib/load-script";
import { bind } from "discourse-common/utils/decorators";
import themeColor from "../lib/themeColor";
export default class DataExplorerBarChart extends Component {
chart;
@ -86,6 +86,7 @@ export default class DataExplorerBarChart extends Component {
}
willDestroy() {
super.willDestroy(...arguments);
this.chart.destroy();
}
}

View File

@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import { debounce } from "discourse-common/utils/decorators";
import { isBlank, isEmpty } from "@ember/utils";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { isBlank, isEmpty } from "@ember/utils";
import { debounce } from "discourse-common/utils/decorators";
export default class ExplorerSchema extends Component {
@tracked filter;

View File

@ -1,6 +1,6 @@
import Component from "@glimmer/component";
import { bind } from "discourse-common/utils/decorators";
import { tracked } from "@glimmer/tracking";
import { bind } from "discourse-common/utils/decorators";
export default class OneTable extends Component {
@tracked open = this.args.table.open;

View File

@ -40,7 +40,7 @@
{{else if (eq this.type "user_id")}}
<EmailGroupUserChooser
@value={{this.value}}
@options={{(hash maximum=1)}}
@options={{hash maximum=1}}
@onChange={{this.updateValue}}
name={{@info.identifier}}
/>

View File

@ -1,11 +1,11 @@
import Component from "@glimmer/component";
import I18n from "I18n";
import Category from "discourse/models/category";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { dasherize } from "@ember/string";
import { isEmpty } from "@ember/utils";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { inject as service } from "@ember/service";
import Category from "discourse/models/category";
import I18n from "I18n";
const layoutMap = {
int: "int",

View File

@ -1,24 +1,24 @@
import Component from "@glimmer/component";
import I18n from "I18n";
import { ajax } from "discourse/lib/ajax";
import getURL from "discourse-common/lib/get-url";
import Badge from "discourse/models/badge";
import { capitalize } from "@ember/string";
import { schedule } from "@ember/runloop";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { schedule } from "@ember/runloop";
import { inject as service } from "@ember/service";
import TopicViewComponent from "./result-types/topic";
import TextViewComponent from "./result-types/text";
import PostViewComponent from "./result-types/post";
import ReltimeViewComponent from "./result-types/reltime";
import { capitalize } from "@ember/string";
import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge";
import getURL from "discourse-common/lib/get-url";
import I18n from "I18n";
import BadgeViewComponent from "./result-types/badge";
import UrlViewComponent from "./result-types/url";
import UserViewComponent from "./result-types/user";
import CategoryViewComponent from "./result-types/category";
import GroupViewComponent from "./result-types/group";
import HtmlViewComponent from "./result-types/html";
import JsonViewComponent from "./result-types/json";
import CategoryViewComponent from "./result-types/category";
import PostViewComponent from "./result-types/post";
import ReltimeViewComponent from "./result-types/reltime";
import TextViewComponent from "./result-types/text";
import TopicViewComponent from "./result-types/topic";
import UrlViewComponent from "./result-types/url";
import UserViewComponent from "./result-types/user";
const VIEW_COMPONENTS = {
topic: TopicViewComponent,

View File

@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import getURL from "discourse-common/lib/get-url";
import { cached } from "@glimmer/tracking";
import { capitalize } from "@ember/string";
import { escapeExpression } from "discourse/lib/utilities";
import { cached } from "@glimmer/tracking";
import getURL from "discourse-common/lib/get-url";
import TextViewComponent from "./result-types/text";
export default class QueryRowContent extends Component {

View File

@ -1,6 +1,6 @@
import Component from "@glimmer/component";
import { isEmpty } from "@ember/utils";
import { htmlSafe } from "@ember/template";
import { isEmpty } from "@ember/utils";
import { convertIconClass, iconHTML } from "discourse-common/lib/icon-library";
export default class Badge extends Component {

View File

@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import FullscreenCodeModal from "discourse/components/modal/fullscreen-code";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import { cached } from "@glimmer/tracking";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import FullscreenCodeModal from "discourse/components/modal/fullscreen-code";
export default class Json extends Component {
@service dialog;

View File

@ -1,6 +1,6 @@
import Component from "@glimmer/component";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
import { htmlSafe } from "@ember/template";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
export default class Reltime extends Component {
get boundDateReplacement() {

View File

@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import getURL from "discourse-common/lib/get-url";
import { bind } from "discourse-common/utils/decorators";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
export default class ShareReport extends Component {
@tracked visible = false;

View File

@ -1,18 +1,19 @@
import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
import showModal from "discourse/lib/show-modal";
import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { Promise } from "rsvp";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import showModal from "discourse/lib/show-modal";
import { bind } from "discourse-common/utils/decorators";
import I18n from "I18n";
import { Promise } from "rsvp";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query";
const NoQuery = Query.create({ name: "No queries", fake: true, group_ids: [] });
export default class PluginsExplorerController extends Controller {
@service("router") router;
@service dialog;
@service appEvents;
@ -264,7 +265,7 @@ export default class PluginsExplorerController extends Controller {
sortByProperty: "last_run_at",
sortDescending: true,
});
this.transitionToRoute({ queryParams: { id: null, params: null } });
this.router.transitionTo({ queryParams: { id: null, params: null } });
}
@action

View File

@ -1,16 +1,16 @@
import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import BookmarkModal from "discourse/components/modal/bookmark";
import { BookmarkFormData } from "discourse/lib/bookmark";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { BookmarkFormData } from "discourse/lib/bookmark";
import {
NO_REMINDER_ICON,
WITH_REMINDER_ICON,
} from "discourse/models/bookmark";
import { action } from "@ember/object";
import { bind } from "discourse-common/utils/decorators";
import { tracked } from "@glimmer/tracking";
import { inject as service } from "@ember/service";
export default class GroupReportsShowController extends Controller {
@service currentUser;

View File

@ -1,5 +1,5 @@
import getURL from "discourse-common/lib/get-url";
import RestModel from "discourse/models/rest";
import getURL from "discourse-common/lib/get-url";
export default class Query extends RestModel {
static updatePropertyNames = [

View File

@ -74,7 +74,7 @@
<div class="desc">
<DTextarea
@value={{this.selectedItem.description}}
@placeholder={{(i18n "explorer.description_placeholder")}}
@placeholder={{i18n "explorer.description_placeholder"}}
@input={{this.setDirty}}
/>
</div>
@ -296,7 +296,7 @@
@field="name"
@labelKey="explorer.query_user"
@order={{this.order}}
@asc={{(not this.sortDescending)}}
@asc={{not this.sortDescending}}
@automatic="true"
/>
</div>
@ -311,7 +311,7 @@
@field="username"
@labelKey="explorer.query_user"
@order={{this.order}}
@asc={{(not this.sortDescending)}}
@asc={{not this.sortDescending}}
@automatic="true"
/>
</div>
@ -331,7 +331,7 @@
@field="last_run_at"
@labelKey="explorer.query_time"
@order={{this.order}}
@asc={{(not this.sortDescending)}}
@asc={{not this.sortDescending}}
@automatic="true"
/>
</div>

View File

@ -16,7 +16,7 @@
<tr>
<td>
<LinkTo
@route={{"group.reports.show"}}
@route="group.reports.show"
@models={{array group.name query.id}}
>
{{query.name}}

View File

@ -5,6 +5,9 @@
"author": "Discourse",
"license": "MIT",
"devDependencies": {
"eslint-config-discourse": "^3.4.0"
"@discourse/lint-configs": "^1.2.0",
"ember-template-lint": "^5.13.0",
"eslint": "^8.54.0",
"prettier": "^2.8.8"
}
}

View File

@ -6,7 +6,6 @@
# version: 0.3
# authors: Riking
# url: https://github.com/discourse/discourse-data-explorer
# transpile_js: true
enabled_site_setting :data_explorer_enabled

View File

@ -64,7 +64,7 @@ describe Jobs::DeleteHiddenQueries do
updated_at: 5.days.ago,
)
subject.execute(nil)
described_class.new.execute(nil)
expect(DiscourseDataExplorer::Query.all.length).to eq(4)
end
end

View File

@ -3,6 +3,10 @@
require "rails_helper"
describe DiscourseDataExplorer::QueryGroupBookmarkable do
subject(:registered_bookmarkable) do
RegisteredBookmarkable.new(DiscourseDataExplorer::QueryGroupBookmarkable)
end
fab!(:admin_user) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:guardian) { Guardian.new(user) }
@ -80,24 +84,24 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do
Fabricate(:bookmark, user: user, bookmarkable: query_group4, name: "something i gotta do also")
end
subject { RegisteredBookmarkable.new(DiscourseDataExplorer::QueryGroupBookmarkable) }
describe "#perform_list_query" do
it "returns all the user's bookmarks" do
expect(subject.perform_list_query(user, guardian).map(&:id)).to match_array(
expect(registered_bookmarkable.perform_list_query(user, guardian).map(&:id)).to match_array(
[bookmark1.id, bookmark2.id, bookmark3.id],
)
end
it "does not return bookmarks made from groups that the user is no longer a member of" do
expect(subject.perform_list_query(user, guardian).map(&:id)).not_to include(bookmark4.id)
expect(registered_bookmarkable.perform_list_query(user, guardian).map(&:id)).not_to include(
bookmark4.id,
)
# remove user from the other groups from which they bookmarked a query
group_user1.delete
group_user2.delete
# bookmarks is now empty, because user is not a member of any Groups with permission to see the query
expect(subject.perform_list_query(user, guardian)).to be_empty
expect(registered_bookmarkable.perform_list_query(user, guardian)).to be_empty
end
end
@ -107,8 +111,8 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do
it "returns bookmarks that match by name" do
ts_query = Search.ts_query(term: "gotta", ts_config: "simple")
expect(
subject.perform_search_query(
subject.perform_list_query(user, guardian),
registered_bookmarkable.perform_search_query(
registered_bookmarkable.perform_list_query(user, guardian),
"%gotta%",
ts_query,
).map(&:id),
@ -118,8 +122,8 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do
it "returns bookmarks that match by Query name" do
ts_query = Search.ts_query(term: "First", ts_config: "simple")
expect(
subject.perform_search_query(
subject.perform_list_query(user, guardian),
registered_bookmarkable.perform_search_query(
registered_bookmarkable.perform_list_query(user, guardian),
"%First%",
ts_query,
).map(&:id),
@ -129,21 +133,21 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do
describe "#can_send_reminder?" do
it "cannot send the reminder if the group is revoked access to the query" do
expect(subject.can_send_reminder?(bookmark1)).to eq(true)
expect(registered_bookmarkable.can_send_reminder?(bookmark1)).to eq(true)
bookmark1.bookmarkable.delete
bookmark1.reload
expect(subject.can_send_reminder?(bookmark1)).to eq(false)
expect(registered_bookmarkable.can_send_reminder?(bookmark1)).to eq(false)
end
end
describe "#reminder_handler" do
it "creates a notification for the user with the correct details" do
expect { subject.send_reminder_notification(bookmark1) }.to change { Notification.count }.by(
1,
)
notif = user.notifications.last
expect(notif.notification_type).to eq(Notification.types[:bookmark_reminder])
expect(notif.data).to eq(
expect { registered_bookmarkable.send_reminder_notification(bookmark1) }.to change {
Notification.count
}.by(1)
notification = user.notifications.last
expect(notification.notification_type).to eq(Notification.types[:bookmark_reminder])
expect(notification.data).to eq(
{
title: bookmark1.bookmarkable.query.name,
bookmarkable_url:
@ -158,26 +162,26 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable do
describe "#can_see?" do
it "returns false if the user is not a member of the group from which they created the bookmark" do
expect(subject.can_see?(guardian, bookmark1)).to eq(true) #Query 1, Group 0
expect(subject.can_see?(guardian, bookmark2)).to eq(true) #Query 1, Group 1
expect(subject.can_see?(guardian, bookmark3)).to eq(true) #Query 2, Group 1
expect(subject.can_see?(guardian, bookmark4)).to eq(false) #Query 1, Group 2
expect(registered_bookmarkable.can_see?(guardian, bookmark1)).to eq(true) # Query 1, Group 0
expect(registered_bookmarkable.can_see?(guardian, bookmark2)).to eq(true) # Query 1, Group 1
expect(registered_bookmarkable.can_see?(guardian, bookmark3)).to eq(true) # Query 2, Group 1
expect(registered_bookmarkable.can_see?(guardian, bookmark4)).to eq(false) # Query 1, Group 2
# remove from Groups 0 and 1
group_user1.delete # Group 0
group_user2.delete # Group 1
guardian.user.reload
expect(subject.can_see?(guardian, bookmark1)).to eq(false)
expect(subject.can_see?(guardian, bookmark2)).to eq(false)
expect(subject.can_see?(guardian, bookmark3)).to eq(false)
expect(subject.can_see?(guardian, bookmark4)).to eq(false)
expect(registered_bookmarkable.can_see?(guardian, bookmark1)).to eq(false)
expect(registered_bookmarkable.can_see?(guardian, bookmark2)).to eq(false)
expect(registered_bookmarkable.can_see?(guardian, bookmark3)).to eq(false)
expect(registered_bookmarkable.can_see?(guardian, bookmark4)).to eq(false)
# And adding the user back to the group, just to be sure.
Fabricate(:group_user, user: user, group: group2)
guardian.user.reload
expect(subject.can_see?(guardian, bookmark4)).to eq(true)
expect(registered_bookmarkable.can_see?(guardian, bookmark4)).to eq(true)
end
end
end

View File

@ -1,13 +1,13 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import {
acceptance,
count,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import I18n from "I18n";
import { test } from "qunit";
import { visit } from "@ember/test-helpers";
acceptance("Data Explorer Plugin | List Queries", function (needs) {
needs.user();

View File

@ -1,7 +1,7 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { test } from "qunit";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Data Explorer Plugin | New Query", function (needs) {
needs.user();

View File

@ -1,10 +1,10 @@
import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
acceptance("Data Explorer Plugin | Param Input", function (needs) {
needs.user();

View File

@ -1,13 +1,13 @@
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import {
acceptance,
exists,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import I18n from "I18n";
import { test } from "qunit";
acceptance("Data Explorer Plugin | Run Query", function (needs) {
needs.user();

View File

@ -1,8 +1,8 @@
import hbs from "htmlbars-inline-precompile";
import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile";
discourseModule(
"Data Explorer Plugin | Integration | Component | data-explorer-bar-chart",

View File

@ -1,3 +1,5 @@
import { click } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
@ -6,8 +8,6 @@ import {
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { click } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import I18n from "I18n";
discourseModule(

1878
yarn.lock

File diff suppressed because it is too large Load Diff