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

Update: add linting and fix lint issues #16

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ wp-config.php
package-lock.json
npm-debug.log*
/node_modules
/dist
/dist
# composer
vendor
composer.lock
yarn.lock
90 changes: 90 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0"?>
<ruleset name="RSD">
<description>RSD PHP Coding Standards</description>

<!-- Scan these files -->
<file>admin/views</file>
<file>frontend</file>
<file>inc</file>=

<!-- Only lint .php files -->
<arg name="extensions" value="php" />

<!-- Show colors in console -->
<arg value="-colors" />

<!-- Ignore warnings, only show errors -->
<!-- <arg value="n" /> -->

<!-- Show sniff codes in all reports -->
<arg value="s" />

<arg name="report" value="full" />

<!-- Use PSR2 as a base -->
<rule ref="PSR2">
<!-- Allow underscores in class and method names (WP standard) -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />

<!-- Allow opening curly brace on the same line with class or function definition -->
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />

<!-- Disabling namespacing -->
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>

<!-- Set indentation to 2 spaces -->
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2" />
<!-- <property name="exact" value="true" /> -->
</properties>
</rule>

<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing">
<properties>
<property name="spacing" value="1" />
</properties>
</rule>

<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration">
<properties>
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
</rule>

<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1" />
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
</rule>

<rule ref="PSR2.ControlStructures.SwitchDeclaration">
<properties>
<property name="indent" value="2" />
</properties>
</rule>

<rule ref="PSR2.Methods.FunctionCallSignature">
<properties>
<property name="indent" value="2" />
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
</rule>

<rule ref="PSR2.ControlStructures.ControlStructureSpacing">
<properties>
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
</rule>

<!-- Exclusions below are for resources/views/ folder -->

</ruleset>
1 change: 0 additions & 1 deletion admin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ yarn.lock
npm-debug.log*
yarn-debug.log*
yarn-error.log*

/dist
48 changes: 24 additions & 24 deletions admin/assets/scripts/components/inputWrapper.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const inputWrapper = (snazzyAdmin) => {
jQuery(document).ready(function ($) {
const inputWrappers = snazzyAdmin.find('.input-wrapper');
jQuery(document).ready(function ($) {
const inputWrappers = snazzyAdmin.find('.input-wrapper');

if (inputWrappers.length) {
inputWrappers.each(function() {
const thisInputWrapper = $(this);
if (inputWrappers.length) {
inputWrappers.each(function () {
const thisInputWrapper = $(this);

const input = thisInputWrapper.find('input[type="text"]');
const inputDOM = input.get(0);
const copyButton = thisInputWrapper.find('.copy-button');
const input = thisInputWrapper.find('input[type="text"]');
const inputDOM = input.get(0);
const copyButton = thisInputWrapper.find('.copy-button');

copyButton.on('click', function() {
inputDOM.focus();
inputDOM.select();
inputDOM.setSelectionRange(0, 99999); // For mobile devices
if (navigator.clipboard) {
navigator.clipboard.writeText(inputDOM.value);
} else {
// Fallback
document.execCommand('copy');
}
});
});
}
});
copyButton.on('click', function () {
inputDOM.focus();
inputDOM.select();
inputDOM.setSelectionRange(0, 99999); // For mobile devices

if (navigator.clipboard) {
navigator.clipboard.writeText(inputDOM.value);
} else {
// Fallback
document.execCommand('copy');
}
});
});
}
});
};

export default inputWrapper;
export default inputWrapper;
16 changes: 9 additions & 7 deletions admin/assets/scripts/components/toggleVisiblity.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const toggleVisibility = (snazzyAdmin) => {
jQuery(document).ready(function ($) {
const toggleSwitchWrapper = snazzyAdmin.find('.toggle-switch');
jQuery(document).ready(function ($) {
const toggleSwitchWrapper = snazzyAdmin.find('.toggle-switch');

toggleSwitchWrapper.each(function() {
const thisSwitchWrapper = $(this);
toggleSwitchWrapper.each(function () {
const thisSwitchWrapper = $(this);

thisSwitchWrapper.find('input[type="checkbox"]').on('change', function() {
thisSwitchWrapper
.find('input[type="checkbox"]')
.on('change', function () {
const _this = $(this);

const showHideElements = _this.data('show-hide-elements');
Expand All @@ -20,8 +22,8 @@ const toggleVisibility = (snazzyAdmin) => {
}
}
});
});
});
});
};

export default toggleVisibility;
export default toggleVisibility;
14 changes: 7 additions & 7 deletions admin/assets/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import toggleVisiblity from './components/toggleVisiblity';
import inputWrapper from './components/inputWrapper';

const main = () => {
jQuery(document).ready(function ($) {
const snazzyAdmin = $(`#${window.SNAZZYWP['pluginSlug']}-admin`);
// COMPONENTS
toggleVisiblity(snazzyAdmin);
inputWrapper(snazzyAdmin);
});
jQuery(document).ready(function ($) {
const snazzyAdmin = $(`#${window.SNAZZYWP['pluginSlug']}-admin`);
// COMPONENTS
toggleVisiblity(snazzyAdmin);
inputWrapper(snazzyAdmin);
});
};

main();
// export default main; --- when we have pro features already.
// export default main; --- when we have pro features already.
Loading