diff --git a/.stylelintrc b/.stylelintrc index f7135165f7..06443a876f 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -3,7 +3,18 @@ "rules": { "property-no-unknown": [ true, { - "ignoreProperties": ["container-type"] + "ignoreProperties": [ + "container-type", + "container" + ] + } + ], + "at-rule-no-unknown": [ + true, { + "ignoreAtRules": [ + "container", + "mixin" + ] } ] }, diff --git a/package.json b/package.json index 4ca62ee007..2d0f87d1bf 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "src/resources/js/**/*.js", "!src/resources/js/**/*.min.js", "!src/resources/js/app/**/*.js", - "!src/resources/js/utils/query-string.js" + "!src/resources/js/utils/query-string.js", + "!src/**/__tests__/**/*.js" ], "stylelint": [ "src/resources/postcss/**/*.pcss", diff --git a/src/modules/components/form/select/component.js b/src/modules/components/form/select/component.js index c50139e3e4..8a522f3f76 100644 --- a/src/modules/components/form/select/component.js +++ b/src/modules/components/form/select/component.js @@ -22,24 +22,25 @@ export default class Select extends PureComponent { options: PropTypes.shape( { label: PropTypes.string, value: PropTypes.any, + map: PropTypes.func, } ), onOptionClick: PropTypes.func.isRequired, optionClassName: PropTypes.string, isOpen: PropTypes.bool.isRequired, value: PropTypes.any, className: PropTypes.string, - } + }; static defaultProps = { onOptionClick: noop, isOpen: true, optionClassName: '', - } + }; _onOptionClick = ( onClose, value, e ) => { this.props.onOptionClick( value, e ); onClose(); - } + }; get selected() { return find( this.props.options, option => option.value === this.props.value ); @@ -66,7 +67,7 @@ export default class Select extends PureComponent { { option.label } ) ) - ) + ); renderToggle = ( { onToggle, isOpen } ) => (
@@ -82,7 +83,7 @@ export default class Select extends PureComponent { />
- ) + ); renderContent = ( { onClose } ) => ( diff --git a/src/modules/elements/accordion/row/template.js b/src/modules/elements/accordion/row/template.js index 42d63b92df..a86fc3f87a 100644 --- a/src/modules/elements/accordion/row/template.js +++ b/src/modules/elements/accordion/row/template.js @@ -23,6 +23,7 @@ class Row extends PureComponent { onClick: PropTypes.func, onClose: PropTypes.func, onOpen: PropTypes.func, + contentId: PropTypes.string, }; static defaultProps = { diff --git a/src/modules/elements/block-icon/index.js b/src/modules/elements/block-icon/index.js index 76bf7fe5b7..f75cce2a68 100644 --- a/src/modules/elements/block-icon/index.js +++ b/src/modules/elements/block-icon/index.js @@ -9,8 +9,10 @@ import React from 'react'; import { TEC } from '@moderntribe/common/icons'; import './style.pcss'; -export default () => ( +const BlockIcon = () => (
); + +export default BlockIcon; diff --git a/src/modules/elements/creatable-select/element.js b/src/modules/elements/creatable-select/element.js index c795a4c215..a84755172e 100644 --- a/src/modules/elements/creatable-select/element.js +++ b/src/modules/elements/creatable-select/element.js @@ -4,8 +4,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import { components } from 'react-select'; -import Select from 'react-select'; +import Select, { components } from 'react-select'; import { Dashicon } from '@wordpress/components'; /** diff --git a/src/modules/elements/day-picker-input/element.js b/src/modules/elements/day-picker-input/element.js index 78b20c131b..6ee1ca56ab 100644 --- a/src/modules/elements/day-picker-input/element.js +++ b/src/modules/elements/day-picker-input/element.js @@ -1,13 +1,15 @@ +/* global DateFormatter */ /** * External dependencies */ import React, { useState, useRef, useMemo, useCallback } from 'react'; import classNames from 'classnames'; -import "react-day-picker/src/style.css"; +import 'react-day-picker/src/style.css'; import { DayPicker } from 'react-day-picker'; import { Popover } from '@wordpress/components'; import { getSettings as getDateSettings } from '@wordpress/date'; import { parse as parseDate } from 'date-fns'; +import PropTypes from 'prop-types'; /** * Internal dependencies @@ -25,7 +27,7 @@ const DatePickerInput = ( props ) => { { + onChange={ () => { } } { ...inputProps } @@ -34,21 +36,25 @@ const DatePickerInput = ( props ) => { ); }; +DatePickerInput.propTypes = { + setPopoverAnchor: PropTypes.func.isRequired, + inputRef: PropTypes.object.isRequired, + onDayChange: PropTypes.func.isRequired, +}; + /** * Converts the date format from moment.js to the Unicode one used in date-fns. * * @see https://github.com/date-fns/date-fns/blob/main/docs/unicodeTokens.md - * * @param {string} momentFormat The moment.js format string to convert. - * * @returns {string} The converted format string. */ -const momentToDateFnsFormatter = (momentFormat) => { +const momentToDateFnsFormatter = ( momentFormat ) => { return momentFormat - .replace('DD', 'dd') - .replace('D', 'd') - .replace('YYYY', 'yyyy') - .replace('YY', 'yy'); + .replace( 'DD', 'dd' ) + .replace( 'D', 'd' ) + .replace( 'YYYY', 'yyyy' ) + .replace( 'YY', 'yy' ); }; const DayPickerInput = ( props ) => { @@ -57,51 +63,51 @@ const DayPickerInput = ( props ) => { const [ isVisible, setIsVisible ] = useState( false ); // Do not memoize this: it could be changed in the context of the Block Editor elsewhere. const phpDateFormat = getDateSettings()?.formats?.date ?? 'MMMM d, y'; - const dateFormatter = useMemo(() => new DateFormatter(), []); - const parsePhpDate = useCallback( - value => dateFormatter.parseDate(value, phpDateFormat), - [phpDateFormat] - ) + const dateFormatter = useMemo( () => new DateFormatter(), [] ); + const parsePhpDate = useCallback( + value => dateFormatter.parseDate( value, phpDateFormat ), + [ phpDateFormat ], + ); const formatPhpDate = useCallback( - date => dateFormatter.formatDate(date, phpDateFormat), - [phpDateFormat] + date => dateFormatter.formatDate( date, phpDateFormat ), + [ phpDateFormat ], ); const toggleVisible = () => { setIsVisible( ( state ) => ! state ); }; - const { value, onDayChange, formatDate, format } = props; + const { value, onDayChange, format } = props; // Convert the format from the moment.js one to date-fns one using Unicode characters. - const dateFnsFormat = momentToDateFnsFormatter(format); + const dateFnsFormat = momentToDateFnsFormatter( format ); - const getSelectedDateInitialState = useCallback((value) => { + const getSelectedDateInitialState = useCallback( ( val ) => { // Try and parse the value using teh date-fns format. - const d = parseDate(value, dateFnsFormat, new Date()); + const d = parseDate( val, dateFnsFormat, new Date() ); - if (d instanceof Date && !isNaN(d)) { + if ( d instanceof Date && ! isNaN( d ) ) { return d; } // Try and parse the value using the PHP date format. - const parsed = parsePhpDate(value); + const parsed = parsePhpDate( value ); return parsed; - }, [dateFnsFormat, parsePhpDate]); + }, [ dateFnsFormat, parsePhpDate ] ); - const [selectedDate, setSelectedDate] = useState(value ? getSelectedDateInitialState(value) : new Date()); + const [ selectedDate, setSelectedDate ] = useState( + value ? getSelectedDateInitialState( value ) : new Date(), + ); /** * Formats the datepicker Date object to the datepicker format. * * @param {Date|null} date The date to format to the datepicker format. - * * @returns {string} The formatted date. */ const formatDatepickerValue = ( date ) => { - // return date ? formatDate( date, 'MMMM d, y', new Date() ) : ''; - return date ? formatPhpDate(date) : ''; + return date ? formatPhpDate( date ) : ''; }; return ( @@ -115,7 +121,7 @@ const DayPickerInput = ( props ) => { /> { isVisible && ( <> - + { setSelectedDate( date ); toggleVisible(); } } - isSelected={true} + isSelected={ true } /> @@ -138,4 +144,10 @@ const DayPickerInput = ( props ) => { ); }; +DayPickerInput.propTypes = { + value: PropTypes.string, + onDayChange: PropTypes.func.isRequired, + format: PropTypes.string.isRequired, +}; + export default DayPickerInput; diff --git a/src/modules/elements/heading/element.js b/src/modules/elements/heading/element.js index db34d26383..530ca60c1e 100644 --- a/src/modules/elements/heading/element.js +++ b/src/modules/elements/heading/element.js @@ -27,6 +27,7 @@ const Heading = ( { level, children, className } ) => { Heading.propTypes = { children: PropTypes.node.isRequired, level: PropTypes.oneOf( [ 1, 2, 3, 4, 5, 6 ] ).isRequired, + className: PropTypes.string, }; export default Heading; diff --git a/src/modules/elements/image-upload/element.js b/src/modules/elements/image-upload/element.js index 9a944733b2..dbd6c114f8 100644 --- a/src/modules/elements/image-upload/element.js +++ b/src/modules/elements/image-upload/element.js @@ -21,6 +21,7 @@ import { wpEditor } from '@moderntribe/common/utils/globals'; import './style.pcss'; const { MediaUpload } = wpEditor; +// eslint-disable-next-line react/display-name, react/prop-types export const renderImageUploadButton = ( disabled, label ) => ( { open } ) => (