Skip to content

Commit

Permalink
Use explicit jQuery import, remove unused eslint globals (#18435)
Browse files Browse the repository at this point in the history
- Don't rely on globals (window.$) for jQuery import
- Remove eslint globals no longer in use
  • Loading branch information
silverwind committed Jan 28, 2022
1 parent 7b04c97 commit 19b017f
Show file tree
Hide file tree
Showing 51 changed files with 76 additions and 18 deletions.
4 changes: 0 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ env:

globals:
__webpack_public_path__: true
CodeMirror: false
Dropzone: false
SimpleMDE: false

settings:
html/html-extensions: [".tmpl"]
Expand All @@ -34,7 +31,6 @@ overrides:
- files: ["web_src/**/*.js", "web_src/**/*.vue", "templates/**/*.tmpl"]
env:
browser: true
jquery: true
node: false
- files: ["templates/**/*.tmpl"]
rules:
Expand Down
1 change: 1 addition & 0 deletions web_src/js/components/ContextPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</template>

<script>
import $ from 'jquery';
import {SvgIcon} from '../svg.js';
const {appSubUrl, i18n} = window.config;
Expand Down
1 change: 1 addition & 0 deletions web_src/js/components/DashboardRepoList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue';
import $ from 'jquery';
import {initVueSvg, vueDelimiters} from './VueComponentLoader.js';

const {appSubUrl, assetUrlPrefix, pageData} = window.config;
Expand Down
1 change: 1 addition & 0 deletions web_src/js/components/RepoBranchTagDropdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue';
import $ from 'jquery';
import {vueDelimiters} from './VueComponentLoader.js';

export function initRepoBranchTagDropdown(selector) {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/admin-common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {csrfToken} = window.config;

export function initAdminCommon() {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/admin-emails.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initAdminEmails() {
function linkEmailAction(e) {
const $this = $(this);
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/admin-users.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initAdminUserListSearchForm() {
const searchForm = window.config.pageData.adminUserListSearchForm;
if (!searchForm) return;
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {copy_success, copy_error} = window.config.i18n;

function onSuccess(btn) {
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import $ from 'jquery';
import 'jquery.are-you-sure';
import {mqBinarySearch} from '../utils.js';
import createDropzone from './dropzone.js';
import {initCompColorPicker} from './comp/ColorPicker.js';

import 'jquery.are-you-sure';

const {csrfToken} = window.config;

export function initGlobalFormDirtyLeaveConfirm() {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/common-issue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {updateIssuesMeta} from './repo-issue.js';

export function initCommonIssue() {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/common-organization.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {initCompLabelEdit} from './comp/LabelEdit.js';

export function initCommonOrganization() {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/ColorPicker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import createColorPicker from '../colorpicker.js';

export function initCompColorPicker() {
Expand Down
5 changes: 3 additions & 2 deletions web_src/js/features/comp/EasyMDE.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import attachTribute from '../tribute.js';

const {appSubUrl} = window.config;
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function importEasyMDE() {
* @returns {null|EasyMDE}
*/
export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) {
if (textarea instanceof jQuery) {
if (textarea instanceof $) {
textarea = textarea[0];
}
if (!textarea) {
Expand Down Expand Up @@ -151,7 +152,7 @@ export function attachEasyMDEToElements(easyMDE) {
* @returns {null|EasyMDE}
*/
export function getAttachedEasyMDE(el) {
if (el instanceof jQuery) {
if (el instanceof $) {
el = el[0];
}
if (!el) {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/ImagePaste.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
const {csrfToken} = window.config;

async function uploadFile(file, uploadUrl) {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/LabelEdit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {initCompColorPicker} from './ColorPicker.js';

export function initCompLabelEdit(selector) {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/MarkupContentPreview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {initMarkupContent} from '../../markup/content.js';

const {csrfToken} = window.config;
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/ReactionSelector.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
const {csrfToken} = window.config;

export function initCompReactionSelector(parent) {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/SearchUserBox.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';

const {appSubUrl} = window.config;
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/comp/WebHookEditor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
const {csrfToken} = window.config;

export function initCompWebHookEditor() {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/contextpopup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from 'jquery';
import Vue from 'vue';

import ContextPopup from '../components/ContextPopup.vue';
import {parseIssueHref} from '../utils.js';

Expand Down
1 change: 0 additions & 1 deletion web_src/js/features/heatmap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Vue from 'vue';

import ActivityHeatmap from '../components/ActivityHeatmap.vue';

export default function initHeatmap() {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/imagediff.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

function getDefaultSvgBoundsIfUndefined(svgXml, src) {
const DefaultSize = 300;
const MaxSize = 99999;
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/install.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initInstall() {
if ($('.page-content.install').length === 0) {
return;
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/features/notification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {appSubUrl, csrfToken, notificationSettings} = window.config;
import $ from 'jquery';

const {appSubUrl, csrfToken, notificationSettings} = window.config;
let notificationSequenceNumber = 0;

export function initNotificationsTable() {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/org-team.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {appSubUrl} = window.config;

export function initOrgTeamSettings() {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-branch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initRepoBranchButton() {
$('.show-create-branch-modal.button').on('click', function () {
$('#create-branch-form')[0].action = $('#create-branch-form').data('base-action') + $(this).data('branch-from-urlcomponent');
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {svg} from '../svg.js';

function changeHash(hash) {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-commit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {csrfToken} = window.config;

export function initRepoEllipsisButton() {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {csrfToken} = window.config;

function getArchive($target, url, first) {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-diff.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import $ from 'jquery';
import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoIssueContentHistory} from './repo-issue-content.js';
import {validateTextareaNonEmpty} from './comp/EasyMDE.js';

const {csrfToken} = window.config;

export function initRepoDiffReviewButton() {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-editor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';
import {initMarkupContent} from '../markup/content.js';
import {createCodeEditor} from './codeeditor.js';

const {csrfToken} = window.config;

let previewFileModes;

function initEditPreviewTab($form) {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-graph.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export default function initRepoGraphGit() {
const graphContainer = document.getElementById('git-graph-container');
if (!graphContainer) return;
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-home.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {stripTags} from '../utils.js';

const {appSubUrl, csrfToken} = window.config;
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-issue-content.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import $ from 'jquery';
import {svg} from '../svg.js';

const {appSubUrl, csrfToken} = window.config;

let i18nTextEdited;
let i18nTextOptions;
let i18nTextDeleteFromHistory;
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';
import attachTribute from './tribute.js';
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-legacy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
import {initCompImagePaste, initEasyMDEImagePaste} from './comp/ImagePaste.js';
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-migrate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {appSubUrl, csrfToken} = window.config;

export function initRepoMigrationStatusChecker() {
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-migration.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const $service = $('#service_type');
const $user = $('#auth_username');
const $pass = $('#auth_password');
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

const {csrfToken} = window.config;

function moveIssue({item, from, to, oldIndex}) {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-release.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import attachTribute from './tribute.js';
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {createMonaco} from './codeeditor.js';
import {initRepoCommonFilterSearchDropdown} from './repo-common.js';

Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-template.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';

const {appSubUrl} = window.config;
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-unicode-escape.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initUnicodeEscapeButton() {
$(document).on('click', 'a.escape-button', (e) => {
e.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/repo-wiki.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery';
import {initMarkupContent} from '../markup/content.js';
import {attachEasyMDEToElements, importEasyMDE, validateTextareaNonEmpty} from './comp/EasyMDE.js';
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/sshkey-helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initSshKeyFormParser() {
// Parse SSH Key
$('#ssh-key-content').on('change paste keyup', function () {
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/features/stopwatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import $ from 'jquery';
import prettyMilliseconds from 'pretty-ms';
const {appSubUrl, csrfToken, notificationSettings, enableTimeTracking} = window.config;

const {appSubUrl, csrfToken, notificationSettings, enableTimeTracking} = window.config;
let updateTimeInterval = null; // holds setInterval id when active

export function initStopwatch() {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/user-auth-webauthn.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import $ from 'jquery';
import {encode, decode} from 'uint8-to-base64';

const {appSubUrl, csrfToken} = window.config;


export function initUserAuthWebAuthn() {
if ($('.user.signin.webauthn-prompt').length === 0) {
return;
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/user-auth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initUserAuthOauth2() {
const $oauth2LoginNav = $('#oauth2-login-navigator');
if ($oauth2LoginNav.length === 0) return;
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/user-settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery';

export function initUserSettings() {
if ($('.user.settings.profile').length > 0) {
$('#username').on('keyup', function () {
Expand Down
1 change: 1 addition & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './publicpath.js';

import $ from 'jquery';
import {initVueEnv} from './components/VueComponentLoader.js';
import {initRepoActivityTopAuthorsChart} from './components/RepoActivityTopAuthors.vue';
import {initDashboardRepoList} from './components/DashboardRepoList.js';
Expand Down
7 changes: 4 additions & 3 deletions web_src/js/markup/tasklist.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import $ from 'jquery';

const preventListener = (e) => e.preventDefault();

/**
* Attaches `input` handlers to markdown rendered tasklist checkboxes in comments.
*
* When a checkbox value changes, the corresponding [ ] or [x] in the markdown string
* is set accordingly and sent to the server. On success it updates the raw-content on
* error it resets the checkbox to its original value.
*/

const preventListener = (e) => e.preventDefault();

export function initMarkupTasklist() {
for (const el of document.querySelectorAll(`.markup[data-can-edit=true]`) || []) {
const container = el.parentNode;
Expand Down

0 comments on commit 19b017f

Please sign in to comment.