-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create GitHub JS lint action #136
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
webpack.config.js | ||
tests/ | ||
dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['@10up/eslint-config/wordpress'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: JS Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
- trunk | ||
pull_request: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
jslint: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Use desired version of NodeJS | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Build | ||
run: npm run build | ||
- name: Generate linting report | ||
run: npm run lint-js -- --output-file eslint-report.json --format json | ||
continue-on-error: true | ||
- name: Annotate code linting results | ||
uses: ataylorme/eslint-annotate-action@1.2.0 | ||
with: | ||
repo-token: '${{ secrets.GITHUB_TOKEN }}' | ||
report-json: 'eslint-report.json' | ||
- name: Update summary | ||
run: | | ||
npm_config_yes=true npx github:10up/eslint-json-to-md --path ./eslint-report.json --output ./eslint-report.md | ||
cat eslint-report.md >> $GITHUB_STEP_SUMMARY | ||
if: ${{ failure() }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,201 @@ | ||
import '../../css/scss/simple-page-ordering.scss'; | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import 'jquery-ui-sortable'; | ||
import 'jquery'; | ||
|
||
const sortable_post_table = window.jQuery('.wp-list-table tbody'); | ||
function update_simple_ordering_callback(response) { | ||
if ( 'children' === response ) { | ||
if (response === 'children') { | ||
window.location.reload(); | ||
return; | ||
} | ||
|
||
var changes = jQuery.parseJSON( response ); | ||
const changes = window.jQuery.parseJSON(response); | ||
|
||
var new_pos = changes.new_pos; | ||
for ( var key in new_pos ) { | ||
if ( 'next' === key ) { | ||
const { new_pos } = changes; | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const key in new_pos) { | ||
if (key === 'next') { | ||
// eslint-disable-next-line no-continue | ||
continue; | ||
} | ||
|
||
var inline_key = document.getElementById('inline_' + key); | ||
if ( null !== inline_key && new_pos.hasOwnProperty(key) ) { | ||
var dom_menu_order = inline_key.querySelector('.menu_order'); | ||
const inline_key = document.getElementById(`inline_${key}`); | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (inline_key !== null && new_pos.hasOwnProperty(key)) { | ||
const dom_menu_order = inline_key.querySelector('.menu_order'); | ||
|
||
if ( undefined !== new_pos[key]['menu_order'] ) { | ||
if ( null !== dom_menu_order ) { | ||
dom_menu_order.textContent = new_pos[key]['menu_order']; | ||
if (undefined !== new_pos[key].menu_order) { | ||
if (dom_menu_order !== null) { | ||
dom_menu_order.textContent = new_pos[key].menu_order; | ||
} | ||
|
||
var dom_post_parent = inline_key.querySelector('.post_parent'); | ||
if ( null !== dom_post_parent ) { | ||
dom_post_parent.textContent = new_pos[key]['post_parent']; | ||
const dom_post_parent = inline_key.querySelector('.post_parent'); | ||
if (dom_post_parent !== null) { | ||
dom_post_parent.textContent = new_pos[key].post_parent; | ||
} | ||
|
||
var post_title = null; | ||
var dom_post_title = inline_key.querySelector('.post_title'); | ||
if ( null !== dom_post_title ) { | ||
let post_title = null; | ||
const dom_post_title = inline_key.querySelector('.post_title'); | ||
if (dom_post_title !== null) { | ||
post_title = dom_post_title.innerHTML; | ||
} | ||
|
||
var dashes = 0; | ||
while ( dashes < new_pos[key]['depth'] ) { | ||
post_title = '— ' + post_title; | ||
let dashes = 0; | ||
while (dashes < new_pos[key].depth) { | ||
post_title = `— ${post_title}`; | ||
dashes++; | ||
} | ||
var dom_row_title = inline_key.parentNode.querySelector('.row-title'); | ||
if ( null !== dom_row_title && null !== post_title ) { | ||
const dom_row_title = inline_key.parentNode.querySelector('.row-title'); | ||
if (dom_row_title !== null && post_title !== null) { | ||
// Decode mdash character before rendering the title. | ||
var textArea = document.createElement('textarea'); | ||
const textArea = document.createElement('textarea'); | ||
textArea.innerHTML = post_title; | ||
dom_row_title.textContent = textArea.value; | ||
} | ||
} else if ( null !== dom_menu_order ) { | ||
} else if (dom_menu_order !== null) { | ||
dom_menu_order.textContent = new_pos[key]; | ||
} | ||
} | ||
} | ||
|
||
if ( changes.next ) { | ||
jQuery.post( ajaxurl, { | ||
action: 'simple_page_ordering', | ||
id: changes.next['id'], | ||
previd: changes.next['previd'], | ||
nextid: changes.next['nextid'], | ||
start: changes.next['start'], | ||
_wpnonce: simple_page_ordering_localized_data._wpnonce, | ||
screen_id: simple_page_ordering_localized_data.screen_id, | ||
excluded: JSON.stringify( changes.next['excluded'] ) | ||
}, update_simple_ordering_callback ); | ||
if (changes.next) { | ||
window.jQuery.post( | ||
window.ajaxurl, | ||
{ | ||
action: 'simple_page_ordering', | ||
id: changes.next.id, | ||
previd: changes.next.previd, | ||
nextid: changes.next.nextid, | ||
start: changes.next.start, | ||
_wpnonce: window.simple_page_ordering_localized_data._wpnonce, | ||
screen_id: window.simple_page_ordering_localized_data.screen_id, | ||
excluded: JSON.stringify(changes.next.excluded), | ||
}, | ||
update_simple_ordering_callback, | ||
); | ||
} else { | ||
jQuery('.spo-updating-row').removeClass('spo-updating-row').find('.check-column').removeClass('spinner is-active'); | ||
window | ||
.jQuery('.spo-updating-row') | ||
.removeClass('spo-updating-row') | ||
.find('.check-column') | ||
.removeClass('spinner is-active'); | ||
sortable_post_table.removeClass('spo-updating').sortable('enable'); | ||
} | ||
} | ||
|
||
var sortable_post_table = jQuery(".wp-list-table tbody"); | ||
sortable_post_table.sortable({ | ||
items: '> tr', | ||
cursor: 'move', | ||
axis: 'y', | ||
containment: 'table.widefat', | ||
cancel: 'input, textarea, button, select, option, .inline-edit-row', | ||
cancel: 'input, textarea, button, select, option, .inline-edit-row', | ||
distance: 2, | ||
opacity: .8, | ||
opacity: 0.8, | ||
tolerance: 'pointer', | ||
create: function() { | ||
jQuery( document ).keydown(function(e) { | ||
var key = e.key || e.keyCode; | ||
if ( 'Escape' === key || 'Esc' === key || 27 === key ) { | ||
sortable_post_table.sortable( 'option', 'preventUpdate', true ); | ||
sortable_post_table.sortable( 'cancel' ); | ||
create() { | ||
window.jQuery(document).keydown(function (e) { | ||
const key = e.key || e.keyCode; | ||
if (key === 'Escape' || key === 'Esc' || key === 27) { | ||
sortable_post_table.sortable('option', 'preventUpdate', true); | ||
sortable_post_table.sortable('cancel'); | ||
} | ||
}); | ||
}, | ||
start: function(e, ui){ | ||
if ( typeof(inlineEditPost) !== 'undefined' ) { | ||
start(e, ui) { | ||
if (typeof inlineEditPost !== 'undefined') { | ||
// eslint-disable-next-line no-undef | ||
inlineEditPost.revert(); | ||
} | ||
ui.placeholder.height(ui.item.height()); | ||
ui.placeholder.empty(); | ||
}, | ||
helper: function(e, ui) { | ||
var children = ui.children(); | ||
for ( var i=0; i<children.length; i++ ) { | ||
var selector = jQuery(children[i]); | ||
selector.width( selector.width() ); | ||
}; | ||
helper(e, ui) { | ||
const children = ui.children(); | ||
for (let i = 0; i < children.length; i++) { | ||
const selector = window.jQuery(children[i]); | ||
selector.width(selector.width()); | ||
} | ||
return ui; | ||
}, | ||
stop: function(e, ui) { | ||
if ( sortable_post_table.sortable( 'option', 'preventUpdate') ) { | ||
sortable_post_table.sortable( 'option', 'preventUpdate', false ); | ||
stop(e, ui) { | ||
if (sortable_post_table.sortable('option', 'preventUpdate')) { | ||
sortable_post_table.sortable('option', 'preventUpdate', false); | ||
} | ||
|
||
// remove fixed widths | ||
ui.item.children().css('width',''); | ||
ui.item.children().css('width', ''); | ||
}, | ||
update: function(e, ui) { | ||
if ( sortable_post_table.sortable( 'option', 'preventUpdate') ) { | ||
sortable_post_table.sortable( 'option', 'preventUpdate', false ); | ||
update(e, ui) { | ||
if (sortable_post_table.sortable('option', 'preventUpdate')) { | ||
sortable_post_table.sortable('option', 'preventUpdate', false); | ||
return; | ||
} | ||
|
||
sortable_post_table.sortable('disable').addClass('spo-updating'); | ||
ui.item.addClass('spo-updating-row'); | ||
ui.item.find('.check-column').addClass('spinner is-active'); | ||
|
||
var postid = ui.item[0].id.substr(5); // post id | ||
const postid = ui.item[0].id.substr(5); // post id | ||
|
||
var prevpostid = false; | ||
var prevpost = ui.item.prev(); | ||
if ( prevpost.length > 0 ) { | ||
let prevpostid = false; | ||
const prevpost = ui.item.prev(); | ||
if (prevpost.length > 0) { | ||
prevpostid = prevpost.attr('id').substr(5); | ||
} | ||
|
||
var nextpostid = false; | ||
var nextpost = ui.item.next(); | ||
if ( nextpost.length > 0 ) { | ||
let nextpostid = false; | ||
const nextpost = ui.item.next(); | ||
if (nextpost.length > 0) { | ||
nextpostid = nextpost.attr('id').substr(5); | ||
} | ||
|
||
// go do the sorting stuff via ajax | ||
jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid, _wpnonce: simple_page_ordering_localized_data._wpnonce, screen_id: simple_page_ordering_localized_data.screen_id, }, update_simple_ordering_callback ); | ||
window.jQuery.post( | ||
window.ajaxurl, | ||
{ | ||
action: 'simple_page_ordering', | ||
id: postid, | ||
previd: prevpostid, | ||
nextid: nextpostid, | ||
_wpnonce: window.simple_page_ordering_localized_data._wpnonce, | ||
screen_id: window.simple_page_ordering_localized_data.screen_id, | ||
}, | ||
update_simple_ordering_callback, | ||
); | ||
|
||
// fix cell colors | ||
var table_rows = document.querySelectorAll('tr.iedit'), | ||
table_row_count = table_rows.length; | ||
while( table_row_count-- ) { | ||
if ( 0 === table_row_count%2 ) { | ||
jQuery(table_rows[table_row_count]).addClass('alternate'); | ||
const table_rows = document.querySelectorAll('tr.iedit'); | ||
let table_row_count = table_rows.length; | ||
while (table_row_count--) { | ||
if (table_row_count % 2 === 0) { | ||
window.jQuery(table_rows[table_row_count]).addClass('alternate'); | ||
} else { | ||
jQuery(table_rows[table_row_count]).removeClass('alternate'); | ||
window.jQuery(table_rows[table_row_count]).removeClass('alternate'); | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
jQuery( function() { | ||
window.jQuery(function () { | ||
// set up click handler for order reset link | ||
jQuery( '#simple-page-ordering-reset' ).on( 'click', function(e) { | ||
window.jQuery('#simple-page-ordering-reset').on('click', function (e) { | ||
e.preventDefault(); | ||
var post_type = jQuery( this ).data( 'posttype' ); | ||
if ( window.confirm( 'Are you sure you want to reset the ' + post_type + ' order?' ) ) { | ||
jQuery.post( ajaxurl, { | ||
action: 'reset_simple_page_ordering', | ||
post_type: post_type, | ||
_wpnonce: simple_page_ordering_localized_data._wpnonce, | ||
screen_id: simple_page_ordering_localized_data.screen_id | ||
}, function() { window.location.reload(); } ); | ||
const post_type = window.jQuery(this).data('posttype'); | ||
// eslint-disable-next-line no-alert | ||
if (window.confirm(`Are you sure you want to reset the ${post_type} order?`)) { | ||
window.jQuery.post( | ||
window.ajaxurl, | ||
{ | ||
action: 'reset_simple_page_ordering', | ||
post_type, | ||
_wpnonce: window.simple_page_ordering_localized_data._wpnonce, | ||
screen_id: window.simple_page_ordering_localized_data.screen_id, | ||
}, | ||
function () { | ||
window.location.reload(); | ||
}, | ||
); | ||
} | ||
} ); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the plugin uses
@wordpress/dependency-extraction-webpack-plugin
,import jquery
should work fine and allow us to avoid the need forwindow.jQuery
throughout.Were you experiencing issues with the import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmgalanakis could you please respond to Peter's comment above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sidsector9 want to handle any final updates here so this can get merged in as part of the 2.5.0 release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response @peterwilsoncc and @jeffpaul. I had very limited bandwidth for the past couple of weeks.
To address @peterwilsoncc concern, I modified the eslint configuration to be able to use
jQuery
without having to do it throughwindow
.This should be good to go @jeffpaul.