Description
Feature Description
The current value for maximum cyclomatic complexity is 15
. Currently in assets/js/googlesitekit/components-gm2/Button.js
, this is overridden with
/* eslint complexity: [ "error", 19 ] */
Fix the eslint cyclomatic complexity issues in this file such that we do not need to override this rule in file-level and above file-level eslint rule can be removed.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
-
ESLint complexity overrides in
assets/js/googlesitekit/components-gm2/Button.js
are removed. -
Simplify the
Button
component to lower its complexity such that it is no no longer flagged by eslint.
Implementation Brief
-
Create a directory
Button
insideassets/js/googlesitekit/components-gm2/
-
Create
index.js
file inside the directory where the mainButton
component will reside. -
Create a component
SemanticButton
. It should returnButtonTag
(either<a>
or<button>
) as in the current component.
site-kit-wp/assets/js/googlesitekit/components-gm2/Button.js
Lines 101 to 126 in f00a02f
-
Accept all necessary props in the
SemanticButton
component which are being used as shown in above snippet. -
Create a component
MaybeTooltip
inassets/js/googlesitekit/components-gm2/Button/
to indicate its conditionality, like this MaybePlaceholderTile.-
This should accept the
children
prop along with other necessary props as can be seen for the below part of the code in current component.
site-kit-wp/assets/js/googlesitekit/components-gm2/Button.js
Lines 139 to 145 in f00a02f
-
It should wrap the
children
with theTooltip
component only when the condition is satisfied, else return thechildren
without wrapping.
site-kit-wp/assets/js/googlesitekit/components-gm2/Button.js
Lines 133 to 137 in f00a02f
-
-
-
Update the main
Button
component insideassets/js/googlesitekit/components-gm2/Button/index.js
- Import the above created components in
Button
and use them in the render method.
- Import the above created components in
-
Move the stories file for the
Button
component to the newButton
folder. -
Remove the old
Button
component and update the imports across code.
Test Coverage
- Write tests for new components.
- Fix any failing tests.
QA Brief
- Ensure that
Button
stories are rendering properly. - A quick smoke test around the components which uses
Button
.