Skip to content

Commit

Permalink
Merge pull request #6608 from ampproject/fix/lgtm-errors
Browse files Browse the repository at this point in the history
Fix LGTM code analysis warnings
  • Loading branch information
westonruter authored Sep 14, 2021
2 parents a8706f7 + 3a7f9cc commit 6822183
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: CodeQL

# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true

on:
push:
# Only run if JS or Python files changed.
Expand Down
2 changes: 1 addition & 1 deletion assets/src/admin/paired-browsing/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function receiveMessage( event ) {
case 'init':
if ( ! initialized ) {
initialized = true;
receiveInit( event.data );
receiveInit();
}
break;
case 'scroll':
Expand Down
3 changes: 1 addition & 2 deletions assets/src/block-editor/components/layout-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import { ReactElement } from 'react';

/**
* WordPress dependencies
Expand All @@ -17,7 +16,7 @@ import { __, sprintf } from '@wordpress/i18n';
* @param {Object} props.attributes Block attributes.
* @param {Function} props.setAttributes Callback to update block attributes.
* @param {Array} props.ampLayoutOptions Layout options.
* @return {ReactElement} Controls.
* @return {JSX.Element} Controls.
*/
const LayoutControls = ( { attributes, setAttributes, ampLayoutOptions } ) => {
const { ampLayout, height, width } = attributes;
Expand Down
3 changes: 1 addition & 2 deletions assets/src/block-editor/components/media-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import { ReactElement } from 'react';

/**
* WordPress dependencies
Expand All @@ -16,7 +15,7 @@ import { __ } from '@wordpress/i18n';
* @param {Object} props Component props.
* @param {string} props.name Block's name.
* @param {string} props.url URL.
* @return {ReactElement} Placeholder.
* @return {JSX.Element} Placeholder.
*/
const MediaPlaceholder = ( { name, url } ) => {
return (
Expand Down
13 changes: 6 additions & 7 deletions assets/src/block-editor/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import { ReactElement } from 'react';
import { isFunction, isObject, isString } from 'lodash';

/**
Expand Down Expand Up @@ -221,8 +220,8 @@ export const removeAmpFitTextFromBlocks = ( settings, name ) => {
* removed and the deprecation of the block and proceed without error.
*
* @see removeAmpFitTextFromBlocks
* @param {ReactElement} element Block save result.
* @return {ReactElement} Modified block if it is of `amp-fit-text` type, otherwise the original element is returned.
* @param {JSX.Element} element Block save result.
* @return {JSX.Element} Modified block if it is of `amp-fit-text` type, otherwise the original element is returned.
*/
export const removeClassFromAmpFitTextBlocks = ( element ) => {
if ( isValidElement( element ) && 'amp-fit-text' === element.type && undefined !== element.props.className ) {
Expand Down Expand Up @@ -352,7 +351,7 @@ export const setImageBlockLayoutAttributes = ( props, layout ) => {
* Default setup for inspector controls.
*
* @param {Object} props Props.
* @return {ReactElement} Inspector Controls.
* @return {JSX.Element} Inspector Controls.
*/
export const setUpInspectorControls = ( props ) => {
const { isSelected } = props;
Expand Down Expand Up @@ -380,7 +379,7 @@ setUpInspectorControls.propTypes = {
*
* @deprecated As of v2.1. Blocks with the `ampLayout` attribute will still be able to use the control.
* @param {Object} props Props.
* @return {ReactElement} Element.
* @return {JSX.Element} Element.
*/
export const AmpLayoutControl = ( props ) => {
const { name, attributes: { ampLayout }, setAttributes } = props;
Expand Down Expand Up @@ -438,7 +437,7 @@ AmpLayoutControl.propTypes = {
*
* @deprecated As of v2.1. Blocks with the `ampNoLoading` attribute will still be able to use the control.
* @param {Object} props Props.
* @return {ReactElement} Element.
* @return {JSX.Element} Element.
*/
export const AmpNoloadingToggle = ( props ) => {
const { attributes: { ampNoLoading }, setAttributes } = props;
Expand Down Expand Up @@ -484,7 +483,7 @@ AmpNoloadingToggle.propTypes = {
* Get AMP Lightbox toggle control.
*
* @param {Object} props Props.
* @return {ReactElement} Element.
* @return {JSX.Element} Element.
*/
const AmpLightboxToggle = ( props ) => {
const { attributes: { ampLightbox, linkTo, ampLayout }, setAttributes } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { ReactNode } from 'react';

/**
* Internal dependencies
Expand All @@ -14,12 +13,12 @@ import { Loading } from '../../../components/loading';
/**
* Notification component used in the block editor sidebar.
*
* @param {Object} props
* @param {ReactNode} props.action Call to action element.
* @param {ReactNode} props.icon Status icon element.
* @param {boolean} props.isLoading Flag indicating if it's a loading message.
* @param {boolean} props.isSmall Flag indicating if the notification is small.
* @param {string} props.message Message text.
* @param {Object} props
* @param {JSX.Element} props.action Call to action element.
* @param {JSX.Element} props.icon Status icon element.
* @param {boolean} props.isLoading Flag indicating if it's a loading message.
* @param {boolean} props.isSmall Flag indicating if the notification is small.
* @param {string} props.message Message text.
*/
export function SidebarNotification( {
action,
Expand Down
2 changes: 1 addition & 1 deletion assets/src/settings-page/plugin-suppression.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export function PluginSuppression() {
</tr>
</thead>
<tbody>
{ Object.keys( suppressiblePlugins || {} ).map( ( pluginKey ) => (
{ Object.keys( suppressiblePlugins ).map( ( pluginKey ) => (
<PluginRow
key={ `plugin-row-${ pluginKey }` }
pluginDetails={ suppressiblePlugins[ pluginKey ] }
Expand Down
11 changes: 2 additions & 9 deletions assets/src/settings-page/supported-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export function SupportedTemplatesFieldset() {
reader_theme: readerTheme,
} = editedOptions || {};

if ( ( 'reader' === themeSupport && 'legacy' === readerTheme ) || ! supportableTemplates ) {
if ( ( 'reader' === themeSupport && 'legacy' === readerTheme ) || ! supportableTemplates?.length ) {
return null;
}

Expand All @@ -256,14 +256,7 @@ export function SupportedTemplatesFieldset() {
} }
/>

{ supportableTemplates
? <SupportedTemplatesCheckboxes supportableTemplates={ supportableTemplates } />
: (
<p>
{ __( 'Your site does not provide any templates to support.', 'amp' ) }
</p>
)
}
<SupportedTemplatesCheckboxes supportableTemplates={ supportableTemplates } />
</>
) : null }
</fieldset>
Expand Down
12 changes: 3 additions & 9 deletions bin/amphtml-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
import glob
import logging
import os
import platform
import re
import shutil
import subprocess
import sys
import tempfile
import collections
import json
import google
from collections import defaultdict
import imp
import re
import urllib

seen_spec_names = set()

Expand Down Expand Up @@ -388,7 +383,7 @@ def ParseRules(repo_directory, out_dir):
descendant_lists[_list.name].append( val.lower() )

# Separate extension scripts from non-extension scripts and gather the versions
extension_scripts = defaultdict(list)
extension_scripts = collections.defaultdict(list)
extension_specs_by_satisfies = dict()
script_tags = []
for script_tag in allowed_tags['script']:
Expand Down Expand Up @@ -682,7 +677,6 @@ def GetTagRules(tag_spec):
tag_rules['disallowed_ancestor'] = disallowed_ancestor_list

if tag_spec.html_format:
html_format_list = []
has_amp_format = False
for html_format in tag_spec.html_format:
if 1 == html_format:
Expand Down Expand Up @@ -767,7 +761,7 @@ def GetTagRules(tag_spec):
tag_rules['unique_warning'] = tag_spec.unique_warning

if tag_spec.HasField('child_tags'):
child_tags = defaultdict( lambda: [] )
child_tags = collections.defaultdict( lambda: [] )
for field in tag_spec.child_tags.ListFields():
if isinstance(field[1], (int)):
child_tags[ field[0].name ] = field[1]
Expand Down Expand Up @@ -953,7 +947,7 @@ def Phpize(data, indent=0):

# Clean up formatting.
# TODO: Just use PHPCBF for this.
php_exported = re.sub( r'^ +', lambda match: ( len(match.group(0))/2 ) * '\t', php_exported, flags=re.MULTILINE )
php_exported = re.sub( r'^ +', lambda match: int( round(len(match.group(0))/2) ) * '\t', php_exported, flags=re.MULTILINE )
php_exported = php_exported.replace( 'array (', 'array(' )
php_exported = re.sub( r' => \n\s+', ' => ', php_exported, flags=re.MULTILINE )
php_exported = re.sub( r'^(\s+)\d+ =>\s*', r'\1', php_exported, flags=re.MULTILINE )
Expand Down

0 comments on commit 6822183

Please sign in to comment.