Skip to content

Commit

Permalink
Merge pull request #723 from Automattic/fix/lint-step
Browse files Browse the repository at this point in the history
Fix the failing linting step
  • Loading branch information
ingeniumed authored May 21, 2024
2 parents 98999f2 + b87cfe9 commit a884b37
Show file tree
Hide file tree
Showing 30 changed files with 3,078 additions and 1,529 deletions.
11 changes: 0 additions & 11 deletions .eslines.json

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.build.js
node_modules
vendor
*.php
38 changes: 38 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require( '@automattic/eslint-plugin-wpvip/init' );

module.exports = {
extends: [ 'plugin:@automattic/wpvip/recommended' ],
root: true,
env: {
jest: true,
},
rules: {
"no-prototype-builtins": 0,
"no-eval": 0,
"complexity": 0,
"camelcase": 0,
"no-undef": 0,
"wpcalypso/import-docblock": 0,
"valid-jsdoc": 0,
"react/prop-types": 0,
"react/react-in-jsx-scope": 0,
"react-hooks/rules-of-hooks": 0,
"no-redeclare": 0,
"no-shadow": 0,
"no-nested-ternary": 0,
"no-var": 0,
"no-unused-vars": 0,
"no-useless-escape": 0,
"prefer-const": 0,
"no-global-assign": 0,
"no-constant-binary-expression": 0,
"valid-typeof": 0,
"eqeqeq": 0,
"radix": 0,
"no-eq-null": 0,
"array-callback-return": 0,
"no-unused-expressions": 0,
"no-alert": 0,
"no-lonely-if": 0,
}
};
6 changes: 3 additions & 3 deletions .github/workflows/e2e-and-js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
- name: Install WordPress with wp-env
run: npm run wp-env start

- name: Run Lint JS
run: npm run lint-js

- name: Run JS tests (Jest)
run: npm run test-jest

- name: Run E2E tests
run: npm run test-e2e

- name: Run Lint JS
run: npm run lint-js
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
vendor
*.php
package-lock.json
package.json
*.build.js
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@automattic/eslint-plugin-wpvip/prettierrc"
2 changes: 1 addition & 1 deletion blocks/dist/custom-status.build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blocks/src/blocks.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Custom Statuses
import './custom-status/block'
import './custom-status/block';
106 changes: 60 additions & 46 deletions blocks/src/custom-status/block.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import './editor.scss';
import './style.scss';

let { __ } = wp.i18n;
let { PluginPostStatusInfo } = wp.editPost;
let { registerPlugin } = wp.plugins;
let { subscribe, dispatch, select, withSelect, withDispatch } = wp.data;
let { compose } = wp.compose;
let { SelectControl } = wp.components;
const { __ } = wp.i18n;
const { PluginPostStatusInfo } = wp.editPost;
const { registerPlugin } = wp.plugins;
const { subscribe, dispatch, select, withSelect, withDispatch } = wp.data;
const { compose } = wp.compose;
const { SelectControl } = wp.components;

/**
* Map Custom Statuses as options for SelectControl
*/
let statuses = window.EditFlowCustomStatuses.map( s => ({ label: s.name, value: s.slug }) );
const statuses = window.EditFlowCustomStatuses.map( s => ( { label: s.name, value: s.slug } ) );

/**
* Subscribe to changes so we can set a default status and update a button's text.
Expand All @@ -28,16 +28,22 @@ subscribe( function () {
const isCleanNewPost = select( 'core/editor' ).isCleanNewPost();
if ( isCleanNewPost ) {
dispatch( 'core/editor' ).editPost( {
status: ef_default_custom_status
status: ef_default_custom_status,
} );
}

// If the save button exists, let's update the text if needed.
maybeUpdateButtonText( document.querySelector( '.editor-post-save-draft' ) );

// The post is being saved, so we need to set up an observer to update the button text when it's back.
if ( buttonTextObserver === null && window.MutationObserver && select( 'core/editor' ).isSavingPost() ) {
buttonTextObserver = createButtonObserver( document.querySelector( '.edit-post-header__settings' ) );
if (
buttonTextObserver === null &&
window.MutationObserver &&
select( 'core/editor' ).isSavingPost()
) {
buttonTextObserver = createButtonObserver(
document.querySelector( '.edit-post-header__settings' )
);
}
} );

Expand All @@ -53,7 +59,7 @@ function createButtonObserver( parentNode ) {
return null;
}

const observer = new MutationObserver( ( mutationsList ) => {
const observer = new MutationObserver( mutationsList => {
for ( const mutation of mutationsList ) {
for ( const node of mutation.addedNodes ) {
maybeUpdateButtonText( node );
Expand All @@ -66,11 +72,16 @@ function createButtonObserver( parentNode ) {
}

function maybeUpdateButtonText( saveButton ) {
/*
/*
* saveButton.children < 1 accounts for when a user hovers over the save button
* and a tooltip is rendered
*/
if ( saveButton && saveButton.children < 1 && ( saveButton.innerText === __( 'Save Draft' ) || saveButton.innerText === __( 'Save as Pending' ) ) ) {
*/
if (
saveButton &&
saveButton.children < 1 &&
( saveButton.innerText === __( 'Save Draft' ) ||
saveButton.innerText === __( 'Save as Pending' ) )
) {
saveButton.innerText = __( 'Save' );
}
}
Expand All @@ -79,48 +90,51 @@ function maybeUpdateButtonText( saveButton ) {
* Custom status component
* @param object props
*/
let EditFlowCustomPostStati = ( { onUpdate, status } ) => (
<PluginPostStatusInfo
className={ `edit-flow-extended-post-status edit-flow-extended-post-status-${status}` }
>
<h4>{ status !== 'publish' ? __( 'Extended Post Status', 'edit-flow' ) : __( 'Extended Post Status Disabled.', 'edit-flow' ) }</h4>

{ status !== 'publish' ? <SelectControl
label=""
value={ status }
options={ statuses }
onChange={ onUpdate }
/> : null }

<small className="edit-flow-extended-post-status-note">
{ status !== 'publish' ? __( `Note: this will override all status settings above.`, 'edit-flow' ) : __( 'To select a custom status, please unpublish the content first.', 'edit-flow' ) }
</small>
</PluginPostStatusInfo>
const EditFlowCustomPostStati = ( { onUpdate, status } ) => (
<PluginPostStatusInfo
className={ `edit-flow-extended-post-status edit-flow-extended-post-status-${ status }` }
>
<h4>
{ status !== 'publish'
? __( 'Extended Post Status', 'edit-flow' )
: __( 'Extended Post Status Disabled.', 'edit-flow' ) }
</h4>

{ status !== 'publish' ? (
<SelectControl label="" value={ status } options={ statuses } onChange={ onUpdate } />
) : null }

<small className="edit-flow-extended-post-status-note">
{ status !== 'publish'
? __( 'Note: this will override all status settings above.', 'edit-flow' )
: __( 'To select a custom status, please unpublish the content first.', 'edit-flow' ) }
</small>
</PluginPostStatusInfo>
);

const mapSelectToProps = ( select ) => {
return {
status: select('core/editor').getEditedPostAttribute('status'),
};
const mapSelectToProps = select => {
return {
status: select( 'core/editor' ).getEditedPostAttribute( 'status' ),
};
};

const mapDispatchToProps = ( dispatch ) => {
return {
onUpdate( status ) {
dispatch( 'core/editor' ).editPost( { status } );
},
};
const mapDispatchToProps = dispatch => {
return {
onUpdate( status ) {
dispatch( 'core/editor' ).editPost( { status } );
},
};
};

let plugin = compose(
withSelect( mapSelectToProps ),
withDispatch( mapDispatchToProps )
const plugin = compose(
withSelect( mapSelectToProps ),
withDispatch( mapDispatchToProps )
)( EditFlowCustomPostStati );

/**
* Kick it off
*/
registerPlugin( 'edit-flow-custom-status', {
icon: 'edit-flow',
render: plugin
icon: 'edit-flow',
render: plugin,
} );
Loading

0 comments on commit a884b37

Please sign in to comment.