Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Feature/use namespace #97

Merged
merged 59 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
692e527
Remove object type hint and add array
dingo-d Jan 15, 2019
a8d57de
Merge pull request #96 from dingo-d/feature/use-namespace
dingo-d Jan 15, 2019
0693dd5
Fix the no standards selected issue
dingo-d Jan 19, 2019
c48ec5b
Remove form wrapper to prevent accidental submission
dingo-d Jan 19, 2019
80039a7
Minor spacing fixes
dingo-d Jan 19, 2019
472dfb3
Update readme and screenshot
dingo-d Feb 12, 2019
1d3dca8
Bump release version to 1.0.0
dingo-d Feb 17, 2019
c1554f3
Store template tags in a transient from API call
dingo-d Feb 17, 2019
05ae467
Add get required headers in the helpers
dingo-d Feb 17, 2019
0407d51
Add a check for PHP files only
dingo-d Feb 17, 2019
fc092a2
Create LICENSE
dingo-d Feb 24, 2019
00a10ce
Readme change
dingo-d Feb 24, 2019
29b0aaa
Update packages
dingo-d Feb 24, 2019
d69fb00
Update travis and eslintingore
dingo-d Feb 24, 2019
a6e6c3d
Bum version and revert to MIT license
dingo-d Feb 24, 2019
84edf45
Merge changes from the branch
dingo-d Feb 24, 2019
30a51c7
Remove License.txt
dingo-d Feb 24, 2019
38593f0
Fix the warnings issue
dingo-d Feb 24, 2019
e0791d2
Add screenshot
dingo-d Feb 24, 2019
260cc05
Update gitignore
dingo-d Feb 24, 2019
a7ebbcc
Add a way to build a zip file on build run
dingo-d Feb 24, 2019
83d6b16
Add fix for #100 issue
dingo-d Feb 24, 2019
740be45
Minor readme validation
dingo-d Feb 24, 2019
63559cb
Update gitignore
dingo-d Feb 24, 2019
986a447
Update webpack
dingo-d Feb 24, 2019
5121170
Fix minor js glitch
dingo-d Feb 24, 2019
6c461da
Add dump autoload to build script
dingo-d Feb 24, 2019
e8a92d6
Update travis
dingo-d Feb 24, 2019
0eef60a
Remove void return type
dingo-d Feb 26, 2019
ccb7bc0
Remove authentication check on activation and raised version compare …
dingo-d Feb 26, 2019
4b8607b
fixes #102
timelsass Mar 1, 2019
c7e263b
don't rely on 'Layout' returning first in api response
timelsass Mar 1, 2019
c8548b0
remove assignment to var
timelsass Mar 1, 2019
ebd0c7a
Merge pull request #106 from timelsass/feature/use-namespace
dingo-d Mar 1, 2019
125220a
only need to check array for .min. at this point
timelsass Mar 1, 2019
a6e1dc4
remove $removed_files unused var
timelsass Mar 1, 2019
fb8026b
reduce cyclomatic complexity
timelsass Mar 1, 2019
7c05081
fixing spacing
timelsass Mar 1, 2019
cc41f60
inverse logic derp
timelsass Mar 1, 2019
c91fca3
fixes #108
timelsass Mar 1, 2019
5ce294d
Add check for node_modules and vendor files
dingo-d Mar 1, 2019
20ce51e
Merge branch 'feature/use-namespace' into update/file-search
timelsass Mar 1, 2019
9068115
fixes #107
timelsass Mar 2, 2019
a7b6ae1
check for iframe
timelsass Mar 2, 2019
7746210
Merge pull request #113 from timelsass/fix/html-output
dingo-d Mar 2, 2019
7acb046
Add new exception
dingo-d Mar 2, 2019
311a7f8
Modify the otput of the themes helper and view file for the admin page
dingo-d Mar 2, 2019
ff586ea
Modify the husky precommit script
dingo-d Mar 2, 2019
f8f6884
fixes #115
timelsass Mar 2, 2019
db47cab
convert to non-yoda
timelsass Mar 3, 2019
8bebc9a
Merge branch 'feature/check-required-files' of https://github.com/tim…
timelsass Mar 3, 2019
a5cc988
add screenshot validation
timelsass Mar 3, 2019
e58a2d1
Merge pull request #111 from timelsass/update/file-search
dingo-d Mar 3, 2019
7b7a90d
remove yoda cond
timelsass Mar 3, 2019
0289832
Merge pull request #121 from timelsass/feature/check-required-files
dingo-d Mar 3, 2019
f17c9e9
Merge branch 'feature/use-namespace' of https://github.com/wptrt/them…
timelsass Mar 4, 2019
0ce97f9
Merge pull request #122 from timelsass/feature/validate-screenshot
dingo-d Mar 4, 2019
06bb42f
Update contributors list
dingo-d Mar 4, 2019
0612ad4
Update readme
dingo-d Mar 4, 2019
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/vendors/*
/vendor/*
/node_modules/*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ vendor/
*.DS_Store
._*

# Exclude final build zip file and temp folder
/theme-sniffer
.theme-sniffer.zip

# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
sudo: false

dist: trusty

cache:
Expand All @@ -13,7 +11,6 @@ cache:
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.3
Expand All @@ -33,6 +30,7 @@ notifications:
branches:
only:
- master
- development

matrix:
fast_finish: true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 WordPress Theme Review Team and contributors.
Copyright (c) 2019 WPTRT

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
58 changes: 42 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[![Travis](https://img.shields.io/travis/WPTRT/theme-sniffer.svg?style=for-the-badge)](https://travis-ci.org/WPTRT/theme-sniffer.svg?branch=master)
[![License: MIT](https://img.shields.io/github/license/WPTRT/theme-sniffer.svg?style=for-the-badge)](https://github.com/WPTRT/theme-sniffer/blob/master/LICENSE)
[![GitHub All Releases](https://img.shields.io/github/downloads/WPTRT/theme-sniffer/total.svg?style=for-the-badge)](https://github.com/WPTRT/theme-sniffer/releases/)

[![Minimum PHP Version](https://img.shields.io/packagist/php-v/wptrt/theme-sniffer.svg?style=for-the-badge&maxAge=3600)](https://packagist.org/packages/wptrt/theme-sniffer)
[![Tested on PHP 7.0 to nightly](https://img.shields.io/badge/tested%20on-PHP%207.0%20|%207.1%20|%207.2%20|%207.3|%20nightly-green.svg?style=for-the-badge&maxAge=2419200)](https://travis-ci.org/WPTRT/theme-sniffer)
[![Number of Contributors](https://img.shields.io/github/contributors/WPTRT/theme-sniffer.svg?maxAge=3600&style=for-the-badge)](https://github.com/WPTRT/theme-sniffer/graphs/contributors)

# Theme Sniffer

* [Description](#description)
Expand All @@ -8,62 +16,80 @@

## Description

Theme Sniffer will help you analyze your theme code, ensuring the PHP and WordPress Coding Standards compatibility.
Theme Sniffer is a plugin utilizing custom sniffs for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) that statically analyzes your theme and ensures that it adheres to WordPress coding conventions, as well as checking your code against PHP version compatibility.

## Requirements

The Theme Sniffer requires:

* PHP 5.6 or higher.
* PHP 7.0 or higher.
* WordPress 4.7 or higher.

## Installation
## Installation - development

### For themes development
### For themes development and checking

* Download [zip file](https://github.com/WPTRT/theme-sniffer/releases/download/0.2.0/theme-sniffer.0.2.0.zip). [Note: Please use this distribution plugin zip. GitHub provided zip will not work.]
* Download [zip file](https://github.com/WPTRT/theme-sniffer/releases/download/0.2.0/theme-sniffer.0.2.0.zip). **Note**: Please use this distribution plugin zip. GitHub provided zip will not work.
* Install this as you normally install a WordPress plugin
* Activate plugin

### For Theme Sniffer development

* Clone this repo under `wp-content/plugins/`
* Clone this repository under `wp-content/plugins/`
* Run `composer install`
* Run `npm install`
* Run `npm run build`
* Activate plugin

__Note__: If you build the plugin this way you'll have extra `node_modules/` and `vendor/` folders which are not required for the plugin to run, and just take up space. They are to be used for the development purposes mainly.
**Note**: If you build the plugin this way you'll have extra `node_modules/` folders which are not required for the plugin to run, and just take up space. They are to be used for the development purposes mainly. Some of the `vendor/` folders are necessary for Theme Sniffer to run

![Screenshot](screenshot.png?raw=true)

## Usage

* Go to `Appearance` -> `Theme Sniffer`
* Go to `Theme Sniffer`
* Select theme from the dropdown
* Select options
* Click `GO`

### Options

* `Select Standard` - Select the standard with which you would like to sniff the theme.
* `Hide Warning` - Enable this to hide warnings.
* `Raw Output` - Enable this to display sniff report in plaintext format. Suitable to copy/paste report to trac ticket.
* `PHP version` - Select the minimum PHP Version to check if your theme will work with that version.
* `Select Standard` - Select the standard with which you would like to sniff the theme
* `Hide Warning` - Enable this to hide warnings
* `Raw Output` - Enable this to display sniff report in plain text format. Suitable to copy/paste report to trac ticket
* `Ignore annotations` - Ignores any comment annotation that might disable the sniff
* `Check only PHP files` - Only checks PHP files, not CSS and JS - use this to prevent any possible memory leaks
* `Minimum PHP version` - Select the minimum PHP Version to check if your theme will work with that version

## Development

Development prerequisites:

* Installed [Node.js](https://nodejs.org/en/)
* Installed [Composer](https://getcomposer.org/)
* Test environment - [Local by Flywheel](https://local.getflywheel.com/), [VVV](https://varyingvagrantvagrants.org/), [Docker](https://www.docker.com/), [MAMP](https://www.mamp.info/en/), [XAMPP](https://www.apachefriends.org/index.html), [WAMP](http://www.wampserver.com/en/) (whatever works for you)

All of the development asset files are located in the `assets/dev/` folder. We have refactored the plugin to use the latest JavaScript development methods. This is why we are using [webpack](https://webpack.js.org/) to bundle our assets.

To start developing, first clone this repo under `wp-content/plugins/`. Then run in the terminal
When wanting to add a new feature fork the plugin. If you are a maintainer create a `feature/*` branch.

`npm start`
To start developing, first clone this repo under `wp-content/plugins/`. Then run in the terminal:

This will run webpack in the watch mode, so your changes will be saved in the build folder on the fly. After you're done making changes, run
`composer install`
`npm install`

Then you can run:

`npm run start`

This will run webpack in the watch mode, so your changes will be saved in the build folder on the fly. After you're done making changes, run:

`npm run build`

This will create the `assets/build/` folder with js and css files that the plugin will use.

When developing JavaScript code keep in mind the separation of concerns principle - data access and business logic should be separate from the presentation. If you 'sniff' (no pun intended) through the js code, you'll see that `index.js` holds all event triggers and calls the method for sniff start that is located in the separate `ThemeSniffer` class. Business logic modules should contain plain JavaScript (no framework), which makes it reusable. Of course, there is still room for imporvement, so if you notice something that could be improved we incurage you to make a PR :)
When developing JavaScript code keep in mind the separation of concerns principle - data access and business logic should be separate from the presentation. If you 'sniff' (no pun intended) through the js code, you'll see that `index.js` holds all event triggers and calls the method for sniff start that is located in the separate `ThemeSniffer` class. Business logic modules should contain plain JavaScript (no framework), which makes it reusable. Of course, there is still room for imporvement, so if you notice something that could be improved we incurage you to make a PR.

The same is valid for PHP code. The business logic is stored in the `src/` folder, the JS and CSS are located in `assets/` folder and the views are located in the `views/` folder.


12 changes: 8 additions & 4 deletions assets/dev/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ $(
const warningHide = $( 'input[name=hide_warning]' ).is( ':checked' );
const outputRaw = $( 'input[name=raw_output]' ).is( ':checked' );
const ignoreAnnotations = $( 'input[name=ignore_annotations]' ).is( ':checked' );
const checkPhpOnly = $( 'input[name=check_php_only]' ).is( ':checked' );
const minPHPVersion = $( 'select[name=minimum_php_version]' ).val();
const themePrefixes = $( 'input[name=theme_prefixes]' ).val();

const selectedRulesets = $( 'input[name="selected_ruleset[]"]:checked' ).map( ( ind, el ) => el.value ).toArray();

themeSniffer.enableAjax();
themeSniffer.themeCheckRunPHPCS( theme, warningHide, outputRaw, ignoreAnnotations, minPHPVersion, selectedRulesets, themePrefixes );
themeSniffer.themeCheckRunPHPCS( theme, warningHide, outputRaw, ignoreAnnotations, checkPhpOnly, minPHPVersion, selectedRulesets, themePrefixes );
}
);

Expand All @@ -46,11 +47,14 @@ $(

$( 'select[name="themename"]' ).on(
'change', () => {
themeSniffer.preventAjax();
if ( options.startNotice.html().length ) {
themeSniffer.preventAjax();

if ( options.sniffReport.length ) {
options.sniffReport.empty();
if ( options.sniffReport.length ) {
options.sniffReport.empty();
}
}

}
);
}
Expand Down
30 changes: 19 additions & 11 deletions assets/dev/scripts/theme-sniffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export default class ThemeSniffer {

$singleItem.find( this.reportItemLine ).text( line );
$singleItem.find( this.reportItemType ).text( type );
$singleItem.find( this.reportItemMessage ).text( message );
if ( message.includes( 'iframe' ) ) {
$singleItem.find( this.reportItemMessage ).text( message );
} else {
$singleItem.find( this.reportItemMessage ).html( message );
}
$singleItem.appendTo( $reportReportTable );
}
);
Expand All @@ -96,29 +100,32 @@ export default class ThemeSniffer {
return report;
}

showNotices() {
this.$startNotice.html( themeSnifferLocalization.checkInProgress ).addClass( this.SHOW_CLASS );
showNotices( message ) {
this.$startNotice.html( message ).addClass( this.SHOW_CLASS );
this.$checkNotice.removeClass( this.SHOW_CLASS );
this.$loader.addClass( this.SHOW_CLASS );
this.$startButton.addClass( this.DISABLED_CLASS );
this.$stopButton.removeClass( this.DISABLED_CLASS );
}

hideNotices() {
this.$startNotice.html( themeSnifferLocalization.checkCompleted ).addClass( this.SHOW_CLASS );
this.$checkNotice.addClass( this.SHOW_CLASS );
hideNotices( message, showNotice ) {
this.$startNotice.html( message ).addClass( this.SHOW_CLASS );
this.$loader.removeClass( this.SHOW_CLASS );
this.$stopButton.addClass( this.DISABLED_CLASS );
this.$startButton.removeClass( this.DISABLED_CLASS );
if ( showNotice ) {
this.$checkNotice.addClass( this.SHOW_CLASS );
}
}

themeCheckRunPHPCS( theme, warningHide, outputRaw, ignoreAnnotations, minPHPVersion, selectedRulesets, themePrefixes ) {
themeCheckRunPHPCS( theme, warningHide, outputRaw, ignoreAnnotations, checkPhpOnly, minPHPVersion, selectedRulesets, themePrefixes ) {

const snifferRunData = {
themeName: theme,
hideWarning: warningHide,
rawOutput: outputRaw,
ignoreAnnotations: ignoreAnnotations,
checkPhpOnly: checkPhpOnly,
minimumPHPVersion: minPHPVersion,
wpRulesets: selectedRulesets,
themePrefixes: themePrefixes,
Expand All @@ -136,7 +143,7 @@ export default class ThemeSniffer {
url: ajaxurl,
data: snifferRunData,
beforeSend: ( jqXHR ) => {
this.showNotices();
this.showNotices( themeSnifferLocalization.checkInProgress );
if ( ! outputRaw ) {
this.$sniffReport.removeClass( this.IS_RAW_CLASS );
}
Expand All @@ -150,7 +157,7 @@ export default class ThemeSniffer {
this.$startNotice.removeClass( this.SHOW_CLASS );

if ( outputRaw ) {
this.hideNotices();
this.hideNotices( themeSnifferLocalization.checkCompleted, true );
const report = this.$sniffReport.addClass( this.IS_RAW_CLASS );
this.renderRaw( response.data, report );
return;
Expand All @@ -161,10 +168,11 @@ export default class ThemeSniffer {
this.$sniffReport.append( this.renderJSON( val ) );
}
);
this.hideNotices();

this.hideNotices( themeSnifferLocalization.checkCompleted, true );
} else {
this.$snifferInfo.addClass( this.SHOW_CLASS ).text( response.data[0].message );
this.hideNotices( themeSnifferLocalization.errorReport, false );
this.$snifferInfo.addClass( this.SHOW_CLASS ).addClass( this.ERROR_CLASS ).text( response.data[0].message );
}
}, ( xhr, textStatus, errorThrown ) => {
throw new Error( `Error: ${errorThrown}: ${xhr} ${textStatus}` );
Expand Down
4 changes: 4 additions & 0 deletions assets/dev/styles/components/_admin-screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
&.is-shown {
display: block;
}

&.is-error {
color: $red-color;
}
}

&__check-done-notice {
Expand Down
Loading