From 19903e42ece8622793e997b2ac25d2444e8d29cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Sat, 21 Dec 2024 14:42:07 +0300 Subject: [PATCH] Import js config for prettier from https://github.com/django/djangoproject.com/pull/1838/ --- .pre-commit-config.yaml | 3 +- .prettierrc | 11 + trac-env/htdocs/js/main.js | 121 ++++---- trac-env/htdocs/js/mobile-menu.js | 22 +- trac-env/htdocs/tickethacks.js | 472 ++++++++++++++++-------------- 5 files changed, 345 insertions(+), 284 deletions(-) create mode 100644 .prettierrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a95e1f1..79d9859 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,7 +45,8 @@ repos: rev: "v3.4.2" hooks: - id: prettier - exclude_types: [html, css, javascript, json, scss] + exclude_types: [html, css, json, scss] + exclude: '(^trac-env\/htdocs\/js\/lib\/.*$)' - repo: https://github.com/tox-dev/pyproject-fmt rev: "v2.5.0" diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..6962fc7 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,11 @@ +{ + "overrides": [ + { + "files": "*.js", + "options": { + "tabWidth": 2, + "singleQuote": true + } + } + ] +} diff --git a/trac-env/htdocs/js/main.js b/trac-env/htdocs/js/main.js index a4290d0..961ecfd 100644 --- a/trac-env/htdocs/js/main.js +++ b/trac-env/htdocs/js/main.js @@ -1,63 +1,70 @@ // Require.js Module Loader - http://requirejs.org requirejs.config({ - paths: { - "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min", - // "jquery": "lib/jquery", -- local version of jquery if desired. - "jquery.inview": "lib/jquery.inview" - } + paths: { + jquery: '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min', + // "jquery": "lib/jquery", -- local version of jquery if desired. + 'jquery.inview': 'lib/jquery.inview', + }, }); -define(function(){ - - var mods = []; - - //detect Class function - function hasClass( className ) { - if (!document.getElementsByClassName) { //class name function in old IE - document.getElementsByClassName = function(search) { - var d = document, elements, pattern, i, results = []; - if (d.querySelectorAll) { // IE8 - return d.querySelectorAll("." + search); - } - if (d.evaluate) { // IE6, IE7 - pattern = ".//*[contains(concat(' ', @class, ' '), ' " + search + " ')]"; - elements = d.evaluate(pattern, d, null, 0, null); - while ((i = elements.iterateNext())) { - results.push(i); - } - } else { - elements = d.getElementsByTagName("*"); - pattern = new RegExp("(^|\\s)" + search + "(\\s|$)"); - for (i = 0; i < elements.length; i++) { - if ( pattern.test(elements[i].className) ) { - results.push(elements[i]); - } - } - } - return results; - }; - } - return !!document.getElementsByClassName( className ).length; //return a boolean - } - - //feature list - if (hasClass('list-features')) { - mods.push('mod/list-feature'); - } - - //collapsing list - if (hasClass('list-collapsing')) { - mods.push('mod/list-collapsing'); - } - - if (hasClass('version-switcher')) { - mods.push('mod/version-switcher'); - } - - if (hasClass('doc-floating-warning')) { - mods.push('mod/floating-warning'); - } - - require(mods); +define(function () { + var mods = []; + + //detect Class function + function hasClass(className) { + if (!document.getElementsByClassName) { + //class name function in old IE + document.getElementsByClassName = function (search) { + var d = document, + elements, + pattern, + i, + results = []; + if (d.querySelectorAll) { + // IE8 + return d.querySelectorAll('.' + search); + } + if (d.evaluate) { + // IE6, IE7 + pattern = + ".//*[contains(concat(' ', @class, ' '), ' " + search + " ')]"; + elements = d.evaluate(pattern, d, null, 0, null); + while ((i = elements.iterateNext())) { + results.push(i); + } + } else { + elements = d.getElementsByTagName('*'); + pattern = new RegExp('(^|\\s)' + search + '(\\s|$)'); + for (i = 0; i < elements.length; i++) { + if (pattern.test(elements[i].className)) { + results.push(elements[i]); + } + } + } + return results; + }; + } + return !!document.getElementsByClassName(className).length; //return a boolean + } + + //feature list + if (hasClass('list-features')) { + mods.push('mod/list-feature'); + } + + //collapsing list + if (hasClass('list-collapsing')) { + mods.push('mod/list-collapsing'); + } + + if (hasClass('version-switcher')) { + mods.push('mod/version-switcher'); + } + + if (hasClass('doc-floating-warning')) { + mods.push('mod/floating-warning'); + } + + require(mods); }); diff --git a/trac-env/htdocs/js/mobile-menu.js b/trac-env/htdocs/js/mobile-menu.js index 435779e..10d6f88 100644 --- a/trac-env/htdocs/js/mobile-menu.js +++ b/trac-env/htdocs/js/mobile-menu.js @@ -1,11 +1,13 @@ -jQuery(document).ready(function($) { - var menu = $('[role="banner"] [role="navigation"]'); - var button = $(''); +jQuery(document).ready(function ($) { + var menu = $('[role="banner"] [role="navigation"]'); + var button = $( + '', + ); - menu.addClass('nav-menu-on'); - button.insertBefore(menu); - button.on('click', function(){ - menu.toggleClass('active'); - button.toggleClass('active') - }); -}) + menu.addClass('nav-menu-on'); + button.insertBefore(menu); + button.on('click', function () { + menu.toggleClass('active'); + button.toggleClass('active'); + }); +}); diff --git a/trac-env/htdocs/tickethacks.js b/trac-env/htdocs/tickethacks.js index 1fbcbef..bc30d1d 100644 --- a/trac-env/htdocs/tickethacks.js +++ b/trac-env/htdocs/tickethacks.js @@ -2,251 +2,291 @@ // Hacks for the ticket page. // -$(function() { - // Don't collapse ticket properties. - $("#modify").parent().removeClass('collapsed'); +$(function () { + // Don't collapse ticket properties. + $('#modify').parent().removeClass('collapsed'); - // - // Link field names to the corresponding sections in the Triaging doc. - // + // + // Link field names to the corresponding sections in the Triaging doc. + // - var linkMap = { - "h_stage": "triage-stages", - "h_ui_ux": "ui-ux", - "h_version": "version", - "h_component": "component", - "h_severity": "severity", - "h_needs_docs": "needs-documentation", - "h_needs_better_patch": "patch-needs-improvement", - "h_cc": "cc", - "h_has_patch": "has-patch", - "h_easy": "easy-pickings", - "h_keywords": "keywords", - "h_needs_tests": "needs-tests" + var linkMap = { + h_stage: 'triage-stages', + h_ui_ux: 'ui-ux', + h_version: 'version', + h_component: 'component', + h_severity: 'severity', + h_needs_docs: 'needs-documentation', + h_needs_better_patch: 'patch-needs-improvement', + h_cc: 'cc', + h_has_patch: 'has-patch', + h_easy: 'easy-pickings', + h_keywords: 'keywords', + h_needs_tests: 'needs-tests', + }; + + $('table.properties th').each(function () { + var $this = $(this); + var anchor = linkMap[$this.attr('id')]; + if (anchor) { + $this.wrapInner(function () { + return ( + "" + ); + }); } + }); - $("table.properties th").each(function(){ - var $this = $(this); - var anchor = linkMap[$this.attr("id")]; - if (anchor) { - $this.wrapInner(function(){ - return ""; - }); + // Show Pull Requests from Github with titles matching any of the following + // patterns: "# ", "#,", "#:", "#) + var ticket_id = window.location.pathname.split('/')[2]; + $.getJSON( + 'https://api.github.com/search/issues?q=repo:django/django+in:title+type:pr+' + + '%23' + + ticket_id + + '%20' + + '+%23' + + ticket_id + + '%2C' + + '+%23' + + ticket_id + + '%3A' + + '+%23' + + ticket_id + + '%29', + function (data) { + var links = data.items.map(function (item) { + if (item.number == ticket_id) { + return undefined; // skip this element if PR id == ticket id } - }); - // Show Pull Requests from Github with titles matching any of the following - // patterns: "# ", "#,", "#:", "#) - var ticket_id = window.location.pathname.split('/')[2]; - $.getJSON("https://api.github.com/search/issues?q=repo:django/django+in:title+type:pr+" - + "%23"+ticket_id+"%20" - + "+%23"+ticket_id+"%2C" - + "+%23"+ticket_id+"%3A" - + "+%23"+ticket_id+"%29", - function(data) { - var links = data.items.map(function(item) { - if (item.number == ticket_id) { - return undefined; // skip this element if PR id == ticket id - } + // open or closed + var pr_state = item.state; + var build_state; + var merged = false; + var url = item.pull_request.html_url; + var link_text = item.number; - // open or closed - var pr_state = item.state; - var build_state; - var merged = false; - var url = item.pull_request.html_url; - var link_text = item.number; + if (pr_state === 'closed') { + link_text = '' + link_text + ''; + } - if (pr_state === "closed") { - link_text = ""+link_text+""; + // Check if our rate limit is exceeded. If it is, just display + // the PRs without additional infos + var core_rate_limit_exceeded = false; + $.ajax({ + url: 'https://api.github.com/rate_limit', + dataType: 'json', + async: false, + success: function (data, textStatus, xhr) { + // We need to perform a maximum of 3 extra requests to get status infos + if (data.resources.core.remaining < 3) { + core_rate_limit_exceeded = true; } + }, + }); + + if (!core_rate_limit_exceeded) { + // Get merge state of PR + $.ajax({ + url: + 'https://api.github.com/repos/django/django/pulls/' + + item.number + + '/merge', + dataType: 'json', + async: false, + success: function (data, textStatus, xhr) { + merged = true; + }, + error: function (xhr) { + if (xhr.status === 404) { + merged = false; + } + }, + }); - // Check if our rate limit is exceeded. If it is, just display - // the PRs without additional infos - var core_rate_limit_exceeded = false; + if (!merged) { + // Check if the PR was merged manually $.ajax({ - url: "https://api.github.com/rate_limit", - dataType: 'json', - async: false, - success: function (data, textStatus, xhr) { - // We need to perform a maximum of 3 extra requests to get status infos - if(data.resources.core.remaining < 3) { - core_rate_limit_exceeded = true; - } - } + url: + 'https://api.github.com/repos/django/django/issues/' + + item.number + + '/comments', + dataType: 'json', + async: false, + success: function (data) { + $.each(data, function (index, value) { + // Look for "merged/fixed in sha1..." + if (value.body.match(/(merged|fixed) in \b[0-9a-f]{40}\b/i)) { + merged = true; + } + }); + }, }); + } - if(!core_rate_limit_exceeded) { - // Get merge state of PR + if (pr_state === 'open') { + // Get build state of PR if pr_state is open + $.ajax({ + url: + 'https://api.github.com/repos/django/django/pulls/' + + item.number, + dataType: 'json', + async: false, + success: function (data) { $.ajax({ - url: "https://api.github.com/repos/django/django/pulls/" + item.number + "/merge", - dataType: 'json', - async: false, - success: function (data, textStatus, xhr) { - merged = true; - }, - error: function (xhr) { - if (xhr.status === 404) { - merged = false; - } + url: data.statuses_url, + dataType: 'json', + async: false, + success: function (data) { + if (data.length > 0) { + build_state = data[0].state; + link_text += ' build:' + build_state; } + }, }); - - if(!merged) { - // Check if the PR was merged manually - $.ajax({ - url: "https://api.github.com/repos/django/django/issues/"+ item.number +"/comments", - dataType: 'json', - async: false, - success: function(data) { - $.each(data, function(index, value) { - // Look for "merged/fixed in sha1..." - if(value.body.match(/(merged|fixed) in \b[0-9a-f]{40}\b/i)) { - merged = true; - } - }); - } - }); - } - - if (pr_state === 'open') { - // Get build state of PR if pr_state is open - $.ajax({ - url: "https://api.github.com/repos/django/django/pulls/" + item.number, - dataType: 'json', - async: false, - success: function (data) { - $.ajax({ - url: data.statuses_url, - dataType: 'json', - async: false, - success: function (data) { - if (data.length > 0) { - build_state = data[0].state; - link_text += " build:" + build_state; - } - } - }); - } - }); - } else { - // if PR state is closed, display if it was merged or not - if (merged === true) { - link_text += " merged"; - } else { - link_text += " unmerged"; - } - } + }, + }); + } else { + // if PR state is closed, display if it was merged or not + if (merged === true) { + link_text += ' merged'; + } else { + link_text += ' unmerged'; } - return "" + link_text + ""; - }); - - var link = 'How to create a pull request'; - if (links.length > 0) { - link = links.join(", "); + } } - $("table.properties").append("Pull Requests:" + link + ""); - }); + return "" + link_text + ''; + }); - // Ticket Triage Guidelines: show next steps based on the ticket's status, - // flags, etc. - function get_boolean_ticket_flag(name) { - return $('#h_' + name).next().text().trim() === 'yes'; - } - function get_ticket_flag(name) { - return $('#h_' + name).next().text().trim(); - } - var stage = get_ticket_flag('stage'); - var ticket_status = $('.trac-status').text().trim(); - var ticket_type = $('.trac-type').text().trim(); - var has_patch = get_boolean_ticket_flag('has_patch'); - var patch_needs_improvement = get_boolean_ticket_flag('needs_better_patch'); - var needs_docs = get_boolean_ticket_flag('needs_docs'); - var needs_tests = get_boolean_ticket_flag('needs_tests'); - var next_steps = []; - var include_link_to_pr_msg = ( - "include a link to the pull request in the ticket comment when making " + - "that update. The usual format is: [https://github.com/django/django/pull/#### PR]." + var link = + 'How to create a pull request'; + if (links.length > 0) { + link = links.join(', '); + } + $('table.properties').append( + 'Pull Requests:' + link + '', + ); + }, + ); + + // Ticket Triage Guidelines: show next steps based on the ticket's status, + // flags, etc. + function get_boolean_ticket_flag(name) { + return ( + $('#h_' + name) + .next() + .text() + .trim() === 'yes' + ); + } + function get_ticket_flag(name) { + return $('#h_' + name) + .next() + .text() + .trim(); + } + var stage = get_ticket_flag('stage'); + var ticket_status = $('.trac-status').text().trim(); + var ticket_type = $('.trac-type').text().trim(); + var has_patch = get_boolean_ticket_flag('has_patch'); + var patch_needs_improvement = get_boolean_ticket_flag('needs_better_patch'); + var needs_docs = get_boolean_ticket_flag('needs_docs'); + var needs_tests = get_boolean_ticket_flag('needs_tests'); + var next_steps = []; + var include_link_to_pr_msg = + 'include a link to the pull request in the ticket comment when making ' + + 'that update. The usual format is: [https://github.com/django/django/pull/#### PR].'; + if (ticket_status == 'closed') { + // TODO (e.g. reopening a wontfix or needsinfo, or what to do in the + // case of a regression caused by the ticket + } else if (stage == 'Unreviewed') { + next_steps.push( + "For bugs: reproduce the bug. If it's a regression, " + + "" + + 'bisect to find the commit where the behavior changed.', + ); + next_steps.push( + 'For new features or cleanups: give a second opinion of the proposal.', ); - if (ticket_status == 'closed') { - // TODO (e.g. reopening a wontfix or needsinfo, or what to do in the - // case of a regression caused by the ticket - } else if (stage == 'Unreviewed') { + next_steps.push( + 'In either case, mark the Triage Stage as "Accepted" if the issue seems valid, ' + + 'ask for additional clarification from the reporter, or close the ticket.', + ); + } else if (stage == 'Accepted') { + if (!has_patch) { + next_steps.push( + "" + + 'To provide a patch by sending a pull request. ' + + "" + + "Claim the ticket when you start working so that someone else doesn't duplicate effort. " + + "Before sending a pull request, review your work against the " + + 'patch review checklist. ' + + 'Check the "Has patch" flag on the ticket after sending a pull request and ' + + include_link_to_pr_msg, + ); + } else { + if (needs_tests) { next_steps.push( - "For bugs: reproduce the bug. If it's a regression, " + - "" + - "bisect to find the commit where the behavior changed." + 'To add tests to the patch, then uncheck the "Needs tests" flag on the ticket.', ); + } + if (needs_docs) { next_steps.push( - "For new features or cleanups: give a second opinion of the proposal." + 'To write documentation for the patch, then uncheck "Needs documentation" on the ticket.', ); + } + if (patch_needs_improvement) { next_steps.push( - "In either case, mark the Triage Stage as \"Accepted\" if the issue seems valid, " + - "ask for additional clarification from the reporter, or close the ticket." + 'To improve the patch as described in the pull request review ' + + 'comments or on this ticket, then uncheck "Patch needs improvement".', ); - } else if (stage == 'Accepted') { - if (!has_patch) { - next_steps.push( - "" + - "To provide a patch by sending a pull request. " + - "" + - "Claim the ticket when you start working so that someone else doesn't duplicate effort. " + - "Before sending a pull request, review your work against the " + - "patch review checklist. " + - "Check the \"Has patch\" flag on the ticket after sending a pull request and " + - include_link_to_pr_msg - ); - } else { - if (needs_tests) { - next_steps.push('To add tests to the patch, then uncheck the "Needs tests" flag on the ticket.'); - } - if (needs_docs) { - next_steps.push('To write documentation for the patch, then uncheck "Needs documentation" on the ticket.'); - } - if (patch_needs_improvement) { - next_steps.push( - "To improve the patch as described in the pull request review " + - "comments or on this ticket, then uncheck \"Patch needs improvement\"." - ); - } - if (!needs_tests && !needs_docs && !patch_needs_improvement) { - next_steps.push( - 'For anyone except the patch author to review the patch using the ' + - '' + - 'patch review checklist and either ' + - 'mark the ticket as "Ready for checkin" if everything looks good, ' + - 'or leave comments for improvement and mark the ticket as ' + - '"Patch needs improvement".' - ); - } else { - next_steps.push("

If creating a new pull request, " + include_link_to_pr_msg); - } - } - } else if (stage == 'Ready for checkin') { + } + if (!needs_tests && !needs_docs && !patch_needs_improvement) { next_steps.push( - 'For a Django committer to do a final review of the patch and merge ' + - 'it if all looks good.' + 'For anyone except the patch author to review the patch using the ' + + '' + + 'patch review checklist and either ' + + 'mark the ticket as "Ready for checkin" if everything looks good, ' + + 'or leave comments for improvement and mark the ticket as ' + + '"Patch needs improvement".', ); - } else if (stage == 'Someday/Maybe') { + } else { next_steps.push( - '

Unknown. The Someday/Maybe triage stage is used ' + - 'to keep track of high-level ideas or long term feature requests.

' + - '

It could be an issue that\'s blocked until a future version of Django ' + - '(if so, Keywords will contain that version number). It could also ' + - 'be an enhancement request that we might consider adding someday to the framework ' + - 'if an excellent patch is submitted.

' + - '

If you\'re interested in contributing to the issue, ' + - 'raising your ideas on the django-developers ' + - 'mailing list certainly wouldn\'t hurt.

' - ); - } - if (next_steps.length) { - $("#ticket").after( - "

According to the " + - "" + - "ticket's flags, the next step(s) to move this issue forward are:

" + - "
  • " + next_steps.join('
  • ') + "
" + - "
" + '

If creating a new pull request, ' + include_link_to_pr_msg, ); + } } + } else if (stage == 'Ready for checkin') { + next_steps.push( + 'For a Django committer to do a final review of the patch and merge ' + + 'it if all looks good.', + ); + } else if (stage == 'Someday/Maybe') { + next_steps.push( + '

Unknown. The Someday/Maybe triage stage is used ' + + 'to keep track of high-level ideas or long term feature requests.

' + + "

It could be an issue that's blocked until a future version of Django " + + '(if so, Keywords will contain that version number). It could also ' + + 'be an enhancement request that we might consider adding someday to the framework ' + + 'if an excellent patch is submitted.

' + + "

If you're interested in contributing to the issue, " + + 'raising your ideas on the django-developers ' + + "mailing list certainly wouldn't hurt.

", + ); + } + if (next_steps.length) { + $('#ticket').after( + "

According to the " + + "" + + "ticket's flags, the next step(s) to move this issue forward are:

" + + '
  • ' + + next_steps.join('
  • ') + + '
' + + '
', + ); + } });