Skip to content
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

Enable @10up/eslint-config/react and fix warnings and erros #2306

Merged
merged 57 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
eaff090
Remove custom rules in .eslintrc.js
Rahmon Aug 10, 2021
ade6f01
Fix JSDoc lint issues in autosuggest.js
Rahmon Aug 10, 2021
0ca009d
Refactor to declare variables after return statement in autosuggest.js
Rahmon Aug 10, 2021
6568e39
Fix JSDoc in related-posts/Edit.js
Rahmon Aug 10, 2021
20e4185
Remove unused 'number' field state in related-posts/Edit.js
Rahmon Aug 10, 2021
bac0e6e
Update to use post ID in key instead of array index in
Rahmon Aug 10, 2021
cbd2d86
Fix JSDoc in related-posts/block.js
Rahmon Aug 10, 2021
e0d3f7d
Fix JSDoc in comments.js
Rahmon Aug 10, 2021
360924a
Fix else block with only a if statement
Rahmon Aug 10, 2021
7314114
Fix else block with only a if statement in dashboard.js
Rahmon Aug 10, 2021
9ce6456
Move variable after return statement
Rahmon Aug 10, 2021
4e509e3
Remove unused React in ordering/index.js
Rahmon Aug 10, 2021
e5255d4
Fix JSDoc issues in pointers.js
Rahmon Aug 10, 2021
42e1837
Disable @wordpress/no-global-event-listener rule in sites-admin.js
Rahmon Aug 10, 2021
0f6034d
Fix JSDoc issues in stats.js
Rahmon Aug 10, 2021
1b9d460
Fix JSDoc in SynonymsEditor.js
Rahmon Aug 10, 2021
5585c6f
Convert SynonymsEditor to arrow function
Rahmon Aug 10, 2021
04d4653
Fix JSDoc to AlternativeEditor.js
Rahmon Aug 10, 2021
8ac9d25
Convert AlternativeEditor component to arrow function
Rahmon Aug 10, 2021
87c751b
Update to use destructuring props in AlternativeEditor.js
Rahmon Aug 10, 2021
3198e17
Fix JSDoc to AlternativesEditor.js
Rahmon Aug 10, 2021
685f5b6
Convert AlternativesEditor component to arrow function
Rahmon Aug 10, 2021
dd62864
Add type attr to button in AlternativesEditor.js
Rahmon Aug 10, 2021
164c463
Add type attr to button in SetsEditor.js
Rahmon Aug 10, 2021
dd492b7
Convert SetsEditor component to arrow function
Rahmon Aug 10, 2021
17963b4
Fix JSDoc to SolrEditor.js
Rahmon Aug 10, 2021
c97ca7c
Fix JSDoc to LinkedMultiInput.js
Rahmon Aug 10, 2021
dc38e44
Convert LinkedMultiInput component to arrow function
Rahmon Aug 10, 2021
dfffae4
Fix JSDoc to MultiInput.js
Rahmon Aug 10, 2021
3184849
Convert MultiInput component to arrow function
Rahmon Aug 10, 2021
2d92df3
Update to use destructuring props in context.js
Rahmon Aug 10, 2021
645d0b0
Fix JSDoc to synonyms/index.js
Rahmon Aug 10, 2021
f9b2b19
Fix JSDoc to synonyms/reducers.js
Rahmon Aug 10, 2021
0fa5762
Fix JSDoc to synonnyms/util.js
Rahmon Aug 10, 2021
034132b
Fix JSDoc to helpers.js
Rahmon Aug 10, 2021
3498b5f
Refactor to declare title as const in pointers.js
Rahmon Aug 10, 2021
cf098e2
Update to use destructuring props in pointers.js
Rahmon Aug 10, 2021
84b6405
Self-closing empty components in pointers.js
Rahmon Aug 11, 2021
f370424
Move searchResults() before render() in pointers.js
Rahmon Aug 11, 2021
e37cf10
Add role and keyboard listener on Add Post button in pointers.js
Rahmon Aug 11, 2021
8661793
Update to use ellipsis character in pointers.js
Rahmon Aug 11, 2021
f6a7136
Remove array index on keys in pointers.js
Rahmon Aug 11, 2021
5f65545
Add role and keyboard listener on Remove Post button in pointers.js
Rahmon Aug 11, 2021
6151c59
Update to use destructuring on getDefaultResults in pointers.js
Rahmon Aug 11, 2021
babc13d
Add missing dependency on useEffect in SynonymsEditor.js
Rahmon Aug 11, 2021
09b3537
Convert SolrEditor component to arrow function
Rahmon Aug 11, 2021
8550b35
Refactor pointers.js
Rahmon Aug 12, 2021
e01f626
Remove unnecesary useEffect and useState from LinkedMultiInput.js
Rahmon Aug 12, 2021
12bc9aa
Add missing dependencies on useEffect in AlternativeEditor.js
Rahmon Aug 12, 2021
0b02fd4
Remove unnecesary useEffect and useState from SolrEditor.js
Rahmon Aug 12, 2021
31722a9
Build assets
Rahmon Aug 12, 2021
3f263ee
Remove unnecessary packages due to 10up-toolkit
Rahmon Aug 13, 2021
8d8c541
Update .babelrc
Rahmon Aug 13, 2021
f6bfe69
Build assets
Rahmon Aug 13, 2021
d5a043b
Merge branch 'develop' into fix/react-warnings-and-errors
Rahmon Aug 13, 2021
a0ece95
Merge branch 'develop' into fix/react-warnings-and-errors
felipeelia Aug 17, 2021
04a8b9d
Merge branch 'develop' into fix/react-warnings-and-errors
felipeelia Aug 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"presets": [
"@10up/babel-preset-default"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
22 changes: 1 addition & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,7 @@ const defaultEslintrc = require('10up-toolkit/config/.eslintrc');

module.exports = {
...defaultEslintrc,
extends: '@10up/eslint-config',
plugins: ['react'],
globals: {
wp: true,
jQuery: true,
},
rules: {
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error',
'no-console': [1],
'no-alert': [1],
camelcase: [1],
'no-debugger': [1],
'no-unused-vars': [1],
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'no-plusplus': [0],
'import/prefer-default-export': [0],
'no-lonely-if': [0],
'func-names': [0],
},
env: {
browser: true,
},
}
};
30 changes: 15 additions & 15 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function selectAutosuggestItem(input, text) {
* Fires events when autosuggest results are clicked,
* and if GA tracking is activated
*
* @param {object} detail - value to pass on to the Custom Event
* @param {Object} detail - value to pass on to the Custom Event
*/
function triggerAutosuggestEvent(detail) {
const event = new CustomEvent('ep-autosuggest-click', { detail });
Expand Down Expand Up @@ -113,7 +113,7 @@ function goToAutosuggestItem(searchTerm, url) {
*
* @param {Node} input - search input
* @param {Node} element - search term result item
* @returns {Function} calls the submitSearchForm function
* @return {Function} calls the submitSearchForm function
*/
function selectItem(input, element) {
if (epas.action === 'navigate') {
Expand All @@ -128,7 +128,7 @@ function selectItem(input, element) {
* Build the search query from the search text - the query is generated in PHP
* and passed into the front end as window.epas = { "query...
*
* @returns {string} json string
* @return {string} json string
*/
function getJsonQuery() {
if (typeof window.epas === 'undefined') {
Expand All @@ -147,9 +147,9 @@ function getJsonQuery() {
*
* @param {string} searchText - user search string
* @param {string} placeholder - placeholder text to replace
* @param {object} options - Autosuggest settings
* @param {Object} options - Autosuggest settings
* @param {string} options.query - JSON query string to pass to ElasticSearch
* @returns {string} json representation of search query
* @return {string} json representation of search query
*/
function buildSearchQuery(searchText, placeholder, { query }) {
const newQuery = replaceGlobally(query, placeholder, searchText);
Expand All @@ -161,7 +161,7 @@ function buildSearchQuery(searchText, placeholder, { query }) {
*
* @param {string} query - json string
* @param {string} searchTerm - user search term
* @returns {object} AJAX object request
* @return {Object} AJAX object request
*/
async function esSearch(query, searchTerm) {
const fetchConfig = {
Expand Down Expand Up @@ -211,7 +211,7 @@ async function esSearch(query, searchTerm) {
*
* @param {Array} options - search results
* @param {string} input - search string
* @returns {boolean} return true
* @return {boolean} return true
*/
function updateAutosuggestBox(options, input) {
let i;
Expand Down Expand Up @@ -295,7 +295,7 @@ function updateAutosuggestBox(options, input) {
/**
* Hide the auto suggest box
*
* @returns {boolean} returns true
* @return {boolean} returns true
*/
function hideAutosuggestBox() {
const lists = document.querySelectorAll('.autosuggest-list');
Expand All @@ -322,7 +322,7 @@ function hideAutosuggestBox() {
*
* @param {Array} hits - ES results
* @param {string} searchTerm - user search term
* @returns {object} formatted hits
* @return {Object} formatted hits
*/
function checkForOrderedPosts(hits, searchTerm) {
const toInsert = {};
Expand Down Expand Up @@ -498,7 +498,7 @@ function init() {
/**
* helper function to get the currently selected result
*
* @returns {number} index of the selected search result
* @return {number} index of the selected search result
*/
const getSelectedResultIndex = () => {
const resultsArr = Array.from(results);
Expand Down Expand Up @@ -579,7 +579,7 @@ function init() {
* Get the searched post types from the search form.
*
* @param {HTMLFormElement} form - form containing the search input field
* @returns {Array} - post types
* @return {Array} - post types
* @since 3.6.0
*/
function getPostTypesFromForm(form) {
Expand All @@ -603,17 +603,17 @@ function init() {
* @param {Node} input - search input field
*/
const fetchResults = async (input) => {
const searchText = input.value;
const placeholder = 'ep_autosuggest_placeholder';
const postTypes = getPostTypesFromForm(input.form);

// retrieves the PHP-genereated query to pass to ElasticSearch
const queryJSON = getJsonQuery();

if (queryJSON.error) {
return;
}

const searchText = input.value;
const placeholder = 'ep_autosuggest_placeholder';
const postTypes = getPostTypesFromForm(input.form);

if (searchText.length >= 2) {
setFormIsLoading(true, input);

Expand Down
11 changes: 3 additions & 8 deletions assets/js/blocks/related-posts/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ class Edit extends Component {
/**
* Setup class
*
* @param {object} props Component properties
* @param {Object} props Component properties
*/
constructor(props) {
super(props);

const {
attributes: { number },
} = props;

this.state = {
posts: false,
number,
};
}

Expand Down Expand Up @@ -87,10 +82,10 @@ class Edit extends Component {
</Placeholder>
) : (
<ul style={{ textAlign: alignment }}>
{displayPosts.map((post, i) => {
{displayPosts.map((post) => {
const titleTrimmed = post.title.rendered.trim();
return (
<li key={i}>
<li key={post.id}>
<a href={post.link}>
{titleTrimmed ? (
<RawHTML>{titleTrimmed}</RawHTML>
Expand Down
6 changes: 3 additions & 3 deletions assets/js/blocks/related-posts/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ registerBlockType('elasticpress/related-posts', {
/**
* Handle edit
*
* @param {object} props Component properties
* @returns {*}
* @param {Object} props Component properties
* @return {Object} <Edit {...props} />
*/
edit(props) {
return <Edit {...props} />;
Expand All @@ -32,7 +32,7 @@ registerBlockType('elasticpress/related-posts', {
/**
* Handle save
*
* @returns {void}
* @return {void}
*/
save() {
return null;
Expand Down
4 changes: 2 additions & 2 deletions assets/js/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function hideResultsBox(inputElement) {
/**
* Update the result list
*
* @param {object} comments Comments to be showed
* @param {Object} comments Comments to be showed
* @param {HTMLInputElement} inputElement The input element used in the widget
*/
const updateResultsBox = (comments, inputElement) => {
Expand Down Expand Up @@ -131,7 +131,7 @@ function setIsLoading(isLoading, inputElement) {
* Fetch comments
*
* @param {HTMLInputElement} inputElement The input element used in the widget
* @returns {(false|Promise)}
* @return {(false|Promise)} Try to fetch comments
*/
function fetchResults(inputElement) {
if (hasMinimumLength(inputElement)) {
Expand Down
48 changes: 22 additions & 26 deletions assets/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,42 +158,38 @@ if (epDash.index_meta) {
// Sync finished
syncStatus = 'finished';
updateSyncDash();
} else {
} else if (epDash.auto_start_index) {
// We are mid sync
if (epDash.auto_start_index) {
syncStatus = 'sync';
syncStatus = 'sync';

history.pushState(
{},
document.title,
document.location.pathname + document.location.search.replace(/&do_sync/, ''),
);
history.pushState(
{},
document.title,
document.location.pathname + document.location.search.replace(/&do_sync/, ''),
);

updateSyncDash();
sync();
} else {
syncStatus = 'pause';
updateSyncDash();
}
updateSyncDash();
sync();
} else {
syncStatus = 'pause';
updateSyncDash();
}
}
} else {
} else if (epDash.auto_start_index) {
// Start a new sync automatically
if (epDash.auto_start_index) {
syncStatus = 'initialsync';
syncStatus = 'initialsync';

updateSyncDash();
updateSyncDash();

syncStatus = 'sync';
syncStatus = 'sync';

history.pushState(
{},
document.title,
document.location.pathname + document.location.search.replace(/&do_sync/, ''),
);
history.pushState(
{},
document.title,
document.location.pathname + document.location.search.replace(/&do_sync/, ''),
);

sync();
}
sync();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion assets/js/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ const facets = document.querySelectorAll('.widget_ep-facet');

facets.forEach((facet) => {
const facetSearchInput = facet.querySelector('.facet-search');
const facetTerms = facet.querySelector('.terms');

if (!facetSearchInput) {
return;
}

const facetTerms = facet.querySelector('.terms');

facet.querySelector('.facet-search').addEventListener(
'keyup',
debounce((event) => {
Expand Down
1 change: 0 additions & 1 deletion assets/js/ordering/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { Pointers } from './pointers';
Expand Down
Loading