Commit a29f56b5 authored by Clement Ho's avatar Clement Ho

Merge branch 'winh-eslint-no-jquery-ajax' into 'master'

Enable ESLint rules to discourage jQuery Ajax

See merge request gitlab-org/gitlab!16643
parents 09604b01 25b20450
...@@ -10,6 +10,7 @@ plugins: ...@@ -10,6 +10,7 @@ plugins:
- import - import
- "@gitlab/i18n" - "@gitlab/i18n"
- "@gitlab/vue-i18n" - "@gitlab/vue-i18n"
- no-jquery
settings: settings:
import/resolver: import/resolver:
webpack: webpack:
...@@ -36,6 +37,11 @@ rules: ...@@ -36,6 +37,11 @@ rules:
vue/no-use-v-if-with-v-for: off vue/no-use-v-if-with-v-for: off
vue/no-v-html: off vue/no-v-html: off
vue/use-v-on-exact: off vue/use-v-on-exact: off
no-jquery/no-ajax: error
no-jquery/no-ajax-events: error
no-jquery/no-load: error
no-jquery/no-load-shorthand: error
no-jquery/no-serialize: error
overrides: overrides:
files: files:
- '**/spec/**/*' - '**/spec/**/*'
......
...@@ -22,6 +22,7 @@ export default class FilterableList { ...@@ -22,6 +22,7 @@ export default class FilterableList {
getPagePath() { getPagePath() {
const action = this.filterForm.getAttribute('action'); const action = this.filterForm.getAttribute('action');
// eslint-disable-next-line no-jquery/no-serialize
const params = $(this.filterForm).serialize(); const params = $(this.filterForm).serialize();
return `${action}${action.indexOf('?') > 0 ? '&' : '?'}${params}`; return `${action}${action.indexOf('?') > 0 ? '&' : '?'}${params}`;
} }
......
...@@ -42,6 +42,7 @@ export default class IntegrationSettingsForm { ...@@ -42,6 +42,7 @@ export default class IntegrationSettingsForm {
// and test the service using provided configuration. // and test the service using provided configuration.
if (this.$form.get(0).checkValidity() && this.canTestService) { if (this.$form.get(0).checkValidity() && this.canTestService) {
e.preventDefault(); e.preventDefault();
// eslint-disable-next-line no-jquery/no-serialize
this.testSettings(this.$form.serialize()); this.testSettings(this.$form.serialize());
} }
} }
......
...@@ -314,6 +314,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -314,6 +314,7 @@ document.addEventListener('DOMContentLoaded', () => {
const action = `${this.action}${link.search === '' ? '?' : '&'}`; const action = `${this.action}${link.search === '' ? '?' : '&'}`;
event.preventDefault(); event.preventDefault();
// eslint-disable-next-line no-jquery/no-serialize
visitUrl(`${action}${$(this).serialize()}`); visitUrl(`${action}${$(this).serialize()}`);
}); });
......
...@@ -1461,6 +1461,7 @@ export default class Notes { ...@@ -1461,6 +1461,7 @@ export default class Notes {
getFormData($form) { getFormData($form) {
const content = $form.find('.js-note-text').val(); const content = $form.find('.js-note-text').val();
return { return {
// eslint-disable-next-line no-jquery/no-serialize
formData: $form.serialize(), formData: $form.serialize(),
formContent: _.escape(content), formContent: _.escape(content),
formAction: $form.attr('action'), formAction: $form.attr('action'),
......
...@@ -6,6 +6,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -6,6 +6,7 @@ document.addEventListener('DOMContentLoaded', () => {
new MiniPipelineGraph({ new MiniPipelineGraph({
container: '.js-commit-pipeline-graph', container: '.js-commit-pipeline-graph',
}).bindEvents(); }).bindEvents();
// eslint-disable-next-line no-jquery/no-load
$('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath); $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
initPipelines(); initPipelines();
}); });
...@@ -21,6 +21,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -21,6 +21,7 @@ document.addEventListener('DOMContentLoaded', () => {
}).bindEvents(); }).bindEvents();
initNotes(); initNotes();
initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight + performanceHeight); initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight + performanceHeight);
// eslint-disable-next-line no-jquery/no-load
$('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath); $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
fetchCommitMergeRequests(); fetchCommitMergeRequests();
initDiffNotes(); initDiffNotes();
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
e.preventDefault(); e.preventDefault();
AP.context.getToken(function(token) { AP.context.getToken(function(token) {
// eslint-disable-next-line no-jquery/no-ajax
$.post(actionUrl, { $.post(actionUrl, {
jwt: token, jwt: token,
namespace_path: $('#namespace-input').val(), namespace_path: $('#namespace-input').val(),
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
e.preventDefault(); e.preventDefault();
AP.context.getToken(function(token) { AP.context.getToken(function(token) {
// eslint-disable-next-line no-jquery/no-ajax
$.ajax({ $.ajax({
url: href, url: href,
method: 'DELETE', method: 'DELETE',
......
...@@ -120,10 +120,12 @@ export default () => { ...@@ -120,10 +120,12 @@ export default () => {
$groupTabContent.on('ajax:success', bindEvents); $groupTabContent.on('ajax:success', bindEvents);
$navElement.one('click', () => { $navElement.one('click', () => {
// eslint-disable-next-line no-jquery/no-ajax
$.get($tabContent.data('initialTemplates')); $.get($tabContent.data('initialTemplates'));
}); });
$groupNavElement.one('click', () => { $groupNavElement.one('click', () => {
// eslint-disable-next-line no-jquery/no-ajax
$.get($groupTabContent.data('initialTemplates')); $.get($groupTabContent.data('initialTemplates'));
}); });
......
...@@ -126,6 +126,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -126,6 +126,7 @@ describe('IntegrationSettingsForm', () => {
spyOn(axios, 'put').and.callThrough(); spyOn(axios, 'put').and.callThrough();
integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form'); integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
// eslint-disable-next-line no-jquery/no-serialize
formData = integrationSettingsForm.$form.serialize(); formData = integrationSettingsForm.$form.serialize();
}); });
......
...@@ -4624,6 +4624,11 @@ eslint-plugin-jest@^22.3.0: ...@@ -4624,6 +4624,11 @@ eslint-plugin-jest@^22.3.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.3.0.tgz#a10f10dedfc92def774ec9bb5bfbd2fb8e1c96d2" resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.3.0.tgz#a10f10dedfc92def774ec9bb5bfbd2fb8e1c96d2"
integrity sha512-P1mYVRNlOEoO5T9yTqOfucjOYf1ktmJ26NjwjH8sxpCFQa6IhBGr5TpKl3hcAAT29hOsRJVuMWmTsHoUVo9FoA== integrity sha512-P1mYVRNlOEoO5T9yTqOfucjOYf1ktmJ26NjwjH8sxpCFQa6IhBGr5TpKl3hcAAT29hOsRJVuMWmTsHoUVo9FoA==
eslint-plugin-no-jquery@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-no-jquery/-/eslint-plugin-no-jquery-2.1.0.tgz#d03b74224c5cfbc7fc0bdd12ce4eb400d09e0c0b"
integrity sha512-5sr5tOJRfuRviyAvFTe/mr80TXWxTteD/JHRuJtDN8q/bxAh16eSKoKLAevLC7wZCRN2iwnEfhQPQV4rp/gYtg==
eslint-plugin-promise@^4.1.1: eslint-plugin-promise@^4.1.1:
version "4.1.1" version "4.1.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.1.1.tgz#1e08cb68b5b2cd8839f8d5864c796f56d82746db" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.1.1.tgz#1e08cb68b5b2cd8839f8d5864c796f56d82746db"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment