Skip to content

Commit 05606e0

Browse files
committed
Adding the Cloud9 plugin to the repo.
1 parent f4d6dda commit 05606e0

File tree

372 files changed

+42212
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+42212
-0
lines changed

images/example.png

62.4 KB
Loading

license.txt

Lines changed: 621 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "phpcs.wpcs",
3+
"description": "Displays warnings in the IDE with the help of PHP CodeSniffer configured with WordPress Coding Standards and PHPCompatibility rules.",
4+
"version": "0.0.1",
5+
"author": "EP4",
6+
"contributors": [
7+
{
8+
"name": "Dave Lavoie",
9+
"email": "dave.lavoie+c9@ep4.com"
10+
}
11+
],
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/EP4-Corporation/c9.ide.language.php.wordpress"
15+
},
16+
"plugins": {
17+
"phpcs.wpcs": {}
18+
},
19+
"categories": ["miscellaneous"],
20+
"licenses": ["GPLv3 or later"]
21+
}

phpcs.wpcs.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
define(function(require, exports, module) {
2+
main.consumes = ["Plugin", "language","ui"];
3+
main.provides = ["phpcs.wpcs"];
4+
return main;
5+
6+
function main(options, imports, register) {
7+
var Plugin = imports.Plugin;
8+
9+
/***** Initialization *****/
10+
var plugin = new Plugin("EP4.com", main.consumes);
11+
var language = imports.language;
12+
var emit = plugin.getEmitter();
13+
var ui = imports.ui;
14+
15+
function load() {
16+
var path = options.packagePath.substr(0, options.packagePath.lastIndexOf("/"));
17+
18+
// Load PHPCS
19+
language.registerLanguageHandler(
20+
path + "/worker/phpcs_handler",
21+
function(err, handler) {
22+
if (err) return err;
23+
// send/receive events using handler.emit/on
24+
},
25+
plugin
26+
);
27+
28+
// Load custom CSS stylesheet.
29+
ui.insertCss(require("text!./style.css"), options.staticPrefix, plugin);
30+
}
31+
32+
/***** Methods *****/
33+
34+
35+
36+
/***** Lifecycle *****/
37+
38+
plugin.on("load", function() {
39+
load();
40+
});
41+
plugin.on("unload", function() {
42+
43+
});
44+
45+
/***** Register and define API *****/
46+
47+
plugin.freezePublicAPI({
48+
49+
});
50+
51+
register(null, {
52+
"phpcs.wpcs": plugin
53+
});
54+
}
55+
});

phpcs.wpcs_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use client";
2+
"use mocha";
3+
4+
define(function(require, exports, module) {
5+
main.consumes = ["plugin.test", "myplugin"];
6+
main.provides = [];
7+
return main;
8+
9+
function main(options, imports, register) {
10+
var test = imports["plugin.test"];
11+
var myplugin = imports.myplugin;
12+
13+
var describe = test.describe;
14+
var it = test.it;
15+
var before = test.before;
16+
var after = test.after;
17+
var beforeEach = test.beforeEach;
18+
var afterEach = test.afterEach;
19+
var assert = test.assert;
20+
var expect = test.expect;
21+
22+
/***** Initialization *****/
23+
24+
describe("The module", function(){
25+
this.timeout(2000);
26+
27+
beforeEach(function() {
28+
});
29+
30+
afterEach(function () {
31+
});
32+
33+
it("has a sync test", function() {
34+
});
35+
36+
it("has a async test", function(done) {
37+
done();
38+
});
39+
40+
it("has a failing test", function() {
41+
assert.equal(10, 11);
42+
});
43+
});
44+
45+
register(null, {});
46+
}
47+
});

server/phpcs/phpcbf.phar

510 KB
Binary file not shown.

server/phpcs/phpcs.phar

510 KB
Binary file not shown.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* PHPCompatibility_AbstractComplexVersionSniff.
4+
*
5+
* @category PHP
6+
* @package PHPCompatibility
7+
* @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8+
*/
9+
10+
/**
11+
* PHPCompatibility_AbstractComplexVersionSniff.
12+
*
13+
* @category PHP
14+
* @package PHPCompatibility
15+
* @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
16+
*/
17+
abstract class PHPCompatibility_AbstractComplexVersionSniff extends PHPCompatibility_Sniff implements PHPCompatibility_ComplexVersionInterface
18+
{
19+
20+
21+
/**
22+
* Handle the retrieval of relevant information and - if necessary - throwing of an
23+
* error/warning for an item.
24+
*
25+
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
26+
* @param int $stackPtr The position of the relevant token in
27+
* the stack.
28+
* @param array $itemInfo Base information about the item.
29+
*
30+
* @return void
31+
*/
32+
public function handleFeature(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $itemInfo)
33+
{
34+
$itemArray = $this->getItemArray($itemInfo);
35+
$errorInfo = $this->getErrorInfo($itemArray, $itemInfo);
36+
37+
if ($this->shouldThrowError($errorInfo) === true) {
38+
$this->addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo);
39+
}
40+
}
41+
42+
43+
/**
44+
* Determine whether an error/warning should be thrown for an item based on collected information.
45+
*
46+
* @param array $errorInfo Detail information about an item.
47+
*
48+
* @return bool
49+
*/
50+
abstract protected function shouldThrowError(array $errorInfo);
51+
52+
53+
/**
54+
* Get an array of the non-PHP-version array keys used in a sub-array.
55+
*
56+
* @return array
57+
*/
58+
protected function getNonVersionArrayKeys()
59+
{
60+
return array();
61+
}
62+
63+
64+
/**
65+
* Retrieve a subset of an item array containing only the array keys which
66+
* contain PHP version information.
67+
*
68+
* @param array $itemArray Version and other information about an item.
69+
*
70+
* @return array Array with only the version information.
71+
*/
72+
protected function getVersionArray(array $itemArray)
73+
{
74+
return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys()));
75+
}
76+
77+
78+
/**
79+
* Get the item name to be used for the creation of the error code and in the error message.
80+
*
81+
* @param array $itemInfo Base information about the item.
82+
* @param array $errorInfo Detail information about an item.
83+
*
84+
* @return string
85+
*/
86+
protected function getItemName(array $itemInfo, array $errorInfo)
87+
{
88+
return $itemInfo['name'];
89+
}
90+
91+
92+
/**
93+
* Get the error message template for a specific sniff.
94+
*
95+
* @return string
96+
*/
97+
abstract protected function getErrorMsgTemplate();
98+
99+
100+
/**
101+
* Allow for concrete child classes to filter the error message before it's passed to PHPCS.
102+
*
103+
* @param string $error The error message which was created.
104+
* @param array $itemInfo Base information about the item this error message applied to.
105+
* @param array $errorInfo Detail information about an item this error message applied to.
106+
*
107+
* @return string
108+
*/
109+
protected function filterErrorMsg($error, array $itemInfo, array $errorInfo)
110+
{
111+
return $error;
112+
}
113+
114+
115+
/**
116+
* Allow for concrete child classes to filter the error data before it's passed to PHPCS.
117+
*
118+
* @param array $data The error data array which was created.
119+
* @param array $itemInfo Base information about the item this error message applied to.
120+
* @param array $errorInfo Detail information about an item this error message applied to.
121+
*
122+
* @return array
123+
*/
124+
protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
125+
{
126+
return $data;
127+
}
128+
129+
130+
}//end class
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* PHPCompatibility_AbstractNewFeatureSniff.
4+
*
5+
* @category PHP
6+
* @package PHPCompatibility
7+
* @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8+
*/
9+
10+
/**
11+
* PPHPCompatibility_AbstractNewFeatureSniff.
12+
*
13+
* @category PHP
14+
* @package PHPCompatibility
15+
* @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
16+
*/
17+
abstract class PHPCompatibility_AbstractNewFeatureSniff extends PHPCompatibility_AbstractComplexVersionSniff
18+
{
19+
20+
21+
/**
22+
* Determine whether an error/warning should be thrown for an item based on collected information.
23+
*
24+
* @param array $errorInfo Detail information about an item.
25+
*
26+
* @return bool
27+
*/
28+
protected function shouldThrowError(array $errorInfo)
29+
{
30+
return ($errorInfo['not_in_version'] !== '');
31+
}
32+
33+
34+
/**
35+
* Retrieve the relevant detail (version) information for use in an error message.
36+
*
37+
* @param array $itemArray Version and other information about the item.
38+
* @param array $itemInfo Base information about the item.
39+
*
40+
* @return array
41+
*/
42+
public function getErrorInfo(array $itemArray, array $itemInfo)
43+
{
44+
$errorInfo = array(
45+
'not_in_version' => '',
46+
'error' => true,
47+
);
48+
49+
$versionArray = $this->getVersionArray($itemArray);
50+
51+
if (empty($versionArray) === false) {
52+
foreach ($versionArray as $version => $present) {
53+
if ($errorInfo['not_in_version'] === '' && $present === false
54+
&& $this->supportsBelow($version) === true
55+
) {
56+
$errorInfo['not_in_version'] = $version;
57+
}
58+
}
59+
}
60+
61+
return $errorInfo;
62+
}
63+
64+
65+
/**
66+
* Get the error message template for this sniff.
67+
*
68+
* @return string
69+
*/
70+
protected function getErrorMsgTemplate()
71+
{
72+
return '%s is not present in PHP version %s or earlier';
73+
}
74+
75+
76+
/**
77+
* Generates the error or warning for this item.
78+
*
79+
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
80+
* @param int $stackPtr The position of the relevant token in
81+
* the stack.
82+
* @param array $itemInfo Base information about the item.
83+
* @param array $errorInfo Array with detail (version) information
84+
* relevant to the item.
85+
*
86+
* @return void
87+
*/
88+
public function addError(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo)
89+
{
90+
$itemName = $this->getItemName($itemInfo, $errorInfo);
91+
$error = $this->getErrorMsgTemplate();
92+
93+
$errorCode = $this->stringToErrorCode($itemName).'Found';
94+
$data = array(
95+
$itemName,
96+
$errorInfo['not_in_version'],
97+
);
98+
99+
$error = $this->filterErrorMsg($error, $itemInfo, $errorInfo);
100+
$data = $this->filterErrorData($data, $itemInfo, $errorInfo);
101+
102+
$this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data);
103+
}
104+
105+
106+
}//end class

0 commit comments

Comments
 (0)