From c3fd91670e30bb70a2e0617be3faff41edaba1ba Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 6 Jul 2022 10:37:54 +0200 Subject: [PATCH] DEV: Update linting setup and fix issues (#17345) Re-lands #16119 and #17298 * Update eslint-config-discourse * Update linting workflow * Prettier-ignore stuff * Update template-lint config * Auto-fix template issues * Fix various template issues Mostly incorrect attributes and unused templates * Prettier js files * Fix template auto-fix regressions * Small css tweak Co-authored-by: Peter Wagenet --- .github/workflows/linting.yml | 5 +- .prettierignore | 6 + .template-lintrc.js | 58 +- .../admin/addon/components/ace-editor.js | 3 +- .../controllers/admin-dashboard-reports.js | 2 +- .../addon/routes/admin-customize-themes.js | 5 +- .../addon/routes/admin-users-list-show.js | 5 +- .../admin/addon/services/admin-tools.js | 7 +- .../admin/addon/templates/api-keys-new.hbs | 4 +- .../admin/addon/templates/api-keys-show.hbs | 2 +- .../admin/addon/templates/badges-show.hbs | 22 +- .../components/admin-theme-editor.hbs | 6 +- .../components/admin-user-field-item.hbs | 4 +- .../admin-web-hook-event-chooser.hbs | 2 +- .../templates/components/embeddable-host.hbs | 2 +- .../components/embedding-setting.hbs | 4 +- .../components/inline-edit-checkbox.hbs | 2 +- .../components/report-filters/bool.hbs | 2 +- .../components/secret-value-list.hbs | 4 +- .../templates/components/simple-list.hbs | 6 +- .../templates/components/site-setting.hbs | 2 +- .../components/site-settings/string.hbs | 4 +- .../templates/components/staff-actions.hbs | 2 +- .../templates/components/themes-list.hbs | 2 +- .../addon/templates/components/value-list.hbs | 2 +- .../components/watched-word-form.hbs | 4 +- .../addon/templates/dashboard_reports.hbs | 4 +- .../addon/templates/email-advanced-test.hbs | 2 +- .../addon/templates/logs/screened-urls.hbs | 2 +- .../templates/modal/admin-add-upload.hbs | 2 +- .../templates/modal/admin-incoming-email.hbs | 2 +- .../templates/modal/admin-install-theme.hbs | 2 +- .../modal/admin-watched-word-test.hbs | 2 +- .../admin/addon/templates/site-text-index.hbs | 2 +- .../addon/templates/watched-words-action.hbs | 2 +- .../addon/templates/web-hooks-show-events.hbs | 4 +- .../admin/addon/templates/web-hooks-show.hbs | 4 +- .../admin/addon/templates/web-hooks.hbs | 4 +- .../confirm-new-email/confirm-new-email.js | 5 +- .../discourse-hbr/raw-handlebars-compiler.js | 3 +- .../javascripts/discourse-widget-hbs/index.js | 4 +- .../app/components/composer-editor.js | 13 +- .../app/components/create-account.js | 10 +- .../discourse/app/components/d-editor.js | 7 +- .../discourse/app/components/d-modal.js | 5 +- .../components/group-imap-email-settings.js | 9 +- .../components/group-smtp-email-settings.js | 9 +- .../discourse/app/controllers/login.js | 5 +- .../app/controllers/preferences/email.js | 7 +- .../discourse/app/controllers/topic.js | 8 +- .../app/controllers/user-invited-show.js | 8 +- .../discourse/app/lib/offset-calculator.js | 4 +- .../javascripts/discourse/app/lib/quote.js | 3 +- .../discourse/app/lib/sticky-avatars.js | 4 +- .../javascripts/discourse/app/lib/uploads.js | 3 +- .../app/lib/uppy-media-optimization-plugin.js | 4 +- .../discourse/app/lib/user-search.js | 3 +- .../discourse/app/lib/utilities.js | 9 +- .../app/mixins/composer-upload-uppy.js | 4 +- .../app/mixins/textarea-text-manipulation.js | 7 +- .../javascripts/discourse/app/models/badge.js | 5 +- .../discourse/app/models/category.js | 4 +- .../javascripts/discourse/app/models/group.js | 4 +- .../dynamic-route-builders.js | 40 +- .../pre-initializers/sniff-capabilities.js | 5 +- .../app/routes/account-created-edit-email.js | 5 +- .../discourse/app/routes/forgot-password.js | 5 +- .../app/services/media-optimization-worker.js | 29 +- .../discourse/app/services/presence.js | 5 +- .../templates/components/bookmark-list.hbs | 4 +- .../app/templates/components/bookmark.hbs | 2 +- .../app/templates/components/choose-topic.hbs | 2 +- .../app/templates/components/date-input.hbs | 2 +- .../app/templates/components/date-picker.hbs | 2 +- .../components/edit-category-tags.hbs | 2 +- .../app/templates/components/emoji-picker.hbs | 6 +- .../templates/components/emoji-uploader.hbs | 2 +- .../templates/components/flag-action-type.hbs | 4 +- .../components/future-date-input.hbs | 2 +- .../components/group-imap-email-settings.hbs | 6 +- .../group-manage-email-settings.hbs | 6 +- .../templates/components/group-navigation.hbs | 2 +- .../components/group-smtp-email-settings.hbs | 12 +- .../groups-form-membership-fields.hbs | 6 +- .../templates/components/html-with-links.hbs | 1 - .../app/templates/components/mobile-nav.hbs | 1 - .../components/preference-checkbox.hbs | 2 +- .../app/templates/components/quote-button.hbs | 2 +- .../components/relative-time-picker.hbs | 2 +- .../components/reviewable-field-text.hbs | 2 +- .../components/reviewable-field-textarea.hbs | 2 +- .../components/search-advanced-options.hbs | 18 +- .../templates/components/sidebar/section.hbs | 2 +- .../templates/components/tag-groups-form.hbs | 2 +- .../components/time-shortcut-picker.hbs | 2 +- .../components/user-fields/confirm.hbs | 2 +- .../templates/components/user-fields/text.hbs | 2 +- .../app/templates/full-page-search.hbs | 2 +- .../discourse/app/templates/group-index.hbs | 2 +- .../discourse/app/templates/groups/index.hbs | 4 +- .../discourse/app/templates/invites/show.hbs | 6 +- .../app/templates/mobile/modal/login.hbs | 4 +- .../discourse/app/templates/mobile/users.hbs | 2 +- .../app/templates/modal/create-account.hbs | 8 +- .../app/templates/modal/create-invite.hbs | 12 +- .../app/templates/modal/group-add-members.hbs | 4 +- .../app/templates/modal/jump-to-post.hbs | 2 +- .../discourse/app/templates/modal/login.hbs | 4 +- .../app/templates/modal/publish-page.hbs | 2 +- .../modal/second-factor-add-security-key.hbs | 2 +- .../modal/second-factor-backup-edit.hbs | 2 +- .../modal/second-factor-edit-security-key.hbs | 2 +- .../templates/modal/second-factor-edit.hbs | 2 +- .../app/templates/modal/share-topic.hbs | 2 +- .../discourse/app/templates/outlet-list.hbs | 1 - .../app/templates/preferences-username.hbs | 2 +- .../app/templates/preferences/account.hbs | 2 +- .../app/templates/preferences/profile.hbs | 2 +- .../app/templates/user/bookmarks.hbs | 2 +- .../discourse/app/templates/users.hbs | 2 +- .../app/widgets/quick-access-notifications.js | 5 +- .../app/widgets/user-notifications-large.js | 5 +- .../acceptance/composer-uploads-uppy-test.js | 6 +- .../discourse/tests/acceptance/users-test.js | 5 +- .../tests/fixtures/badges-fixture.js | 492 ++--- .../tests/fixtures/category-fixtures.js | 13 +- .../fixtures/concerns/notification-types.js | 1 - .../tests/fixtures/dashboard-general.js | 4 +- .../tests/fixtures/dashboard-new-features.js | 2 +- .../discourse/tests/fixtures/dashboard.js | 4 +- .../tests/fixtures/directory-fixtures.js | 112 +- .../tests/fixtures/discovery-fixtures.js | 1355 ++++++------ .../discourse/tests/fixtures/drafts.js | 27 +- .../tests/fixtures/group-fixtures.js | 212 +- .../tests/fixtures/groups-fixtures.js | 16 +- .../tests/fixtures/notification-fixtures.js | 9 +- .../discourse/tests/fixtures/pending-posts.js | 8 +- .../discourse/tests/fixtures/poll.js | 182 +- .../discourse/tests/fixtures/post.js | 29 +- .../fixtures/private-messages-fixtures.js | 24 +- .../discourse/tests/fixtures/problems.js | 4 +- .../discourse/tests/fixtures/reports-bulk.js | 72 +- .../discourse/tests/fixtures/reports.js | 8 +- .../tests/fixtures/search-fixtures.js | 9 +- .../tests/fixtures/session-fixtures.js | 6 +- .../discourse/tests/fixtures/site-fixtures.js | 5 +- .../discourse/tests/fixtures/site-settings.js | 18 +- .../tests/fixtures/static-fixtures.js | 2 +- .../discourse/tests/fixtures/top-fixtures.js | 533 ++--- .../discourse/tests/fixtures/topic.js | 146 +- .../discourse/tests/fixtures/user-badges.js | 36 +- .../discourse/tests/fixtures/user-fixtures.js | 82 +- .../tests/helpers/create-pretender.js | 5 +- .../javascripts/discourse/tests/index.html | 32 +- .../components/emoji-uploader-test.js | 6 +- .../topic-notifications-button-test.js | 3 +- .../widgets/hamburger-menu-test.js | 4 +- .../tests/unit/lib/pretty-text-test.js | 6 +- .../unit/lib/uppy-checksum-plugin-test.js | 33 +- .../uppy-media-optimization-plugin-test.js | 14 +- .../tests/unit/models/post-stream-test.js | 36 +- .../tests/unit/models/report-test.js | 183 +- .../addon/engines/discourse-markdown-it.js | 3 +- .../discourse-markdown/bbcode-block.js | 3 +- .../engines/discourse-markdown/mentions.js | 5 +- .../discourse-markdown/upload-protocol.js | 5 +- .../addon/components/category-chooser.js | 6 +- .../select-kit/addon/mixins/utils.js | 3 +- .../select-kit/select-kit-filter.hbs | 3 +- .../templates/components/invite-list.hbs | 2 +- .../components/wizard-field-checkboxes.hbs | 2 +- .../components/wizard-field-text.hbs | 2 +- .../components/wizard-field-textarea.hbs | 2 +- app/assets/stylesheets/common/admin/api.scss | 1 + lib/javascripts/messageformat-lookup.js | 4 +- lib/pretty_text/shims.js | 4 +- package.json | 2 +- .../discourse-local-dates-create-form.hbs | 6 +- .../initializers/discourse-local-dates.js | 5 +- .../discourse-local-dates.js | 5 +- .../acceptance/local-dates-quoting-test.js | 48 +- .../templates/modal/poll-ui-builder.hbs | 8 +- .../initializers/extend-for-poll.js | 4 +- .../javascripts/acceptance/poll-quote-test.js | 3 +- .../acceptance/poll-results-test.js | 30 +- yarn.lock | 1844 ++++++++++------- 186 files changed, 3235 insertions(+), 3127 deletions(-) delete mode 100644 app/assets/javascripts/discourse/app/templates/components/html-with-links.hbs delete mode 100644 app/assets/javascripts/discourse/app/templates/components/mobile-nav.hbs delete mode 100644 app/assets/javascripts/discourse/app/templates/outlet-list.hbs diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 97f0236bbb5..ae3bd97e507 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -86,8 +86,9 @@ jobs: if: ${{ always() }} run: | yarn ember-template-lint \ - app/assets/javascripts \ - plugins/**/assets/javascripts + --no-error-on-unmatched-pattern \ + "app/assets/javascripts/**/*.hbs" \ + "plugins/**/assets/javascripts/**/*.hbs" - name: English locale lint (core) if: ${{ always() }} diff --git a/.prettierignore b/.prettierignore index 50cabc43a52..fff97dce442 100644 --- a/.prettierignore +++ b/.prettierignore @@ -22,4 +22,10 @@ app/assets/javascripts/discourse/tests/fixtures spec/ node_modules/ dist/ +tmp/ + **/*.rb +**/*.hbs +**/*.html +**/*.json +**/*.md diff --git a/.template-lintrc.js b/.template-lintrc.js index 604f813f523..e3fc07b48d6 100644 --- a/.template-lintrc.js +++ b/.template-lintrc.js @@ -1,58 +1,9 @@ module.exports = { - extends: "recommended", - ignore: ["**/*.raw"], + plugins: ["ember-template-lint-plugin-discourse"], + extends: "discourse:recommended", rules: { - "block-indentation": true, - "deprecated-render-helper": true, - "eol-last": "always", - "linebreak-style": true, - "link-rel-noopener": "strict", - "no-abstract-roles": true, - "no-args-paths": true, - "no-attrs-in-components": true, - "no-debugger": true, - "no-duplicate-attributes": true, - "no-extra-mut-helper-argument": true, - "no-html-comments": true, - "no-index-component-invocation": true, - "no-inline-styles": false, - "no-input-block": true, - "no-input-tagname": true, - "no-implicit-this": { - allow: [ - 'loading-spinner' - ] - }, - "no-invalid-interactive": true, - "no-invalid-link-text": true, - "no-invalid-meta": true, - "no-invalid-role": true, - "no-log": true, - "no-negated-condition": true, - "no-nested-interactive": true, - "no-multiple-empty-lines": true, - "no-obsolete-elements": true, - "no-outlet-outside-routes": true, - "no-partial": true, - "no-positive-tabindex": false, - "no-quoteless-attributes": true, - "no-shadowed-elements": true, - "no-trailing-spaces": true, - "no-triple-curlies": true, - "no-unbound": true, - "no-unnecessary-concat": true, - "no-unnecessary-component-helper": true, - "no-unused-block-params": true, - quotes: "double", - "require-button-type": true, - "require-iframe-title": true, - "require-valid-alt-text": false, - "self-closing-void-elements": true, - "simple-unless": true, - "style-concatenation": true, - "table-groups": true, - "link-href-attributes": false, + "no-capital-arguments": false, // TODO: we extensively use `args` argument name "no-curly-component-invocation": { allow: [ // These are helpers, not components @@ -64,5 +15,8 @@ module.exports = { "mobile-directory-item-label", ], }, + "no-implicit-this": { + allow: ["loading-spinner"], + }, }, }; diff --git a/app/assets/javascripts/admin/addon/components/ace-editor.js b/app/assets/javascripts/admin/addon/components/ace-editor.js index 88c46ed9c57..58c1d0b8aa8 100644 --- a/app/assets/javascripts/admin/addon/components/ace-editor.js +++ b/app/assets/javascripts/admin/addon/components/ace-editor.js @@ -5,7 +5,8 @@ import I18n from "I18n"; import { bind, observes } from "discourse-common/utils/decorators"; import { on } from "@ember/object/evented"; -const COLOR_VARS_REGEX = /\$(primary|secondary|tertiary|quaternary|header_background|header_primary|highlight|danger|success|love)(\s|;|-(low|medium|high))/g; +const COLOR_VARS_REGEX = + /\$(primary|secondary|tertiary|quaternary|header_background|header_primary|highlight|danger|success|love)(\s|;|-(low|medium|high))/g; export default Component.extend({ mode: "css", diff --git a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-reports.js b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-reports.js index 51437f22f04..09741ede964 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-dashboard-reports.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-dashboard-reports.js @@ -12,7 +12,7 @@ export default Controller.extend({ "filter", "siteSettings.dashboard_hidden_reports" ) - filterReports(reports, filter) { + filteredReports(reports, filter) { if (filter) { filter = filter.toLowerCase(); reports = reports.filter((report) => { diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js index 5eeae3a5516..8734675eff2 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js +++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js @@ -32,8 +32,9 @@ export default Route.extend({ actions: { installModal() { - const currentTheme = this.controllerFor("adminCustomizeThemes.show") - .model; + const currentTheme = this.controllerFor( + "adminCustomizeThemes.show" + ).model; if (currentTheme && currentTheme.warnUnassignedComponent) { showUnassignedComponentWarning(currentTheme, (result) => { if (!result) { diff --git a/app/assets/javascripts/admin/addon/routes/admin-users-list-show.js b/app/assets/javascripts/admin/addon/routes/admin-users-list-show.js index d4f71e6120c..80eb675049d 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-users-list-show.js +++ b/app/assets/javascripts/admin/addon/routes/admin-users-list-show.js @@ -12,8 +12,9 @@ export default DiscourseRoute.extend({ const routeName = "adminUsersList.show"; if (transition.targetName === routeName) { - const params = transition.routeInfos.find((a) => a.name === routeName) - .params; + const params = transition.routeInfos.find( + (a) => a.name === routeName + ).params; const controller = this.controllerFor(routeName); if (controller) { controller.setProperties({ diff --git a/app/assets/javascripts/admin/addon/services/admin-tools.js b/app/assets/javascripts/admin/addon/services/admin-tools.js index a90df7de8ee..17266be8229 100644 --- a/app/assets/javascripts/admin/addon/services/admin-tools.js +++ b/app/assets/javascripts/admin/addon/services/admin-tools.js @@ -46,9 +46,10 @@ export default Service.extend({ }); controller.setProperties({ postId: opts.postId, postEdit: opts.postEdit }); - return (user.adminUserView - ? Promise.resolve(user) - : AdminUser.find(user.get("id")) + return ( + user.adminUserView + ? Promise.resolve(user) + : AdminUser.find(user.get("id")) ).then((loadedUser) => { controller.setProperties({ user: loadedUser, diff --git a/app/assets/javascripts/admin/addon/templates/api-keys-new.hbs b/app/assets/javascripts/admin/addon/templates/api-keys-new.hbs index 3c9c5310d05..91c0800098e 100644 --- a/app/assets/javascripts/admin/addon/templates/api-keys-new.hbs +++ b/app/assets/javascripts/admin/addon/templates/api-keys-new.hbs @@ -16,7 +16,7 @@ {{else}} - + @@ -76,7 +76,7 @@ {{#each act.params as |p|}} - + {{/each}} diff --git a/app/assets/javascripts/admin/addon/templates/api-keys-show.hbs b/app/assets/javascripts/admin/addon/templates/api-keys-show.hbs index 43ae76c3ce7..f1db529b84a 100644 --- a/app/assets/javascripts/admin/addon/templates/api-keys-show.hbs +++ b/app/assets/javascripts/admin/addon/templates/api-keys-show.hbs @@ -11,7 +11,7 @@ {{#if this.editingDescription}} - + {{else}} {{if this.model.description this.model.description (i18n "admin.api.no_description")}} diff --git a/app/assets/javascripts/admin/addon/templates/badges-show.hbs b/app/assets/javascripts/admin/addon/templates/badges-show.hbs index 60948580a6b..520790be3b3 100644 --- a/app/assets/javascripts/admin/addon/templates/badges-show.hbs +++ b/app/assets/javascripts/admin/addon/templates/badges-show.hbs @@ -3,14 +3,14 @@
{{#if this.readOnly}} - +

{{i18n "admin.badges.read_only_setting_help"}}

{{else}} - + {{/if}}
@@ -56,28 +56,28 @@
{{#if this.buffered.system}} -