Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Mar 28, 2017
0 parents commit 411df51
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
44 changes: 44 additions & 0 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

# Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

# Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

# Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

# Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

# Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "pre/trailing-commas",
"license": "MIT",
"require": {
"pre/plugin": "^0.6"
},
"autoload": {
"files": [
"src/bootstrap.php",
"src/parsers.php"
]
},
"require-dev": {
"phpunit/phpunit": "^5.0"
},
"autoload-dev": {
"psr-4": {
"Pre\\TrailingCommas\\": "tests"
}
}
}
7 changes: 7 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright Christopher Pitt

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="false"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Pre Trailing Commas

Documentation can be found at [preprocess.io](https://preprocess.io/docs#trailing-commas).

## Versioning

This library follows [Semver](http://semver.org). According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with `public` visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep `protected` methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.
3 changes: 3 additions & 0 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

Pre\addMacroPath(__DIR__ . "/macros.pre");
28 changes: 28 additions & 0 deletions src/macros.pre
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

macro {
·chain(
·either(
function,
·token(T_STRING),
·token(T_VARIABLE)
)·function_name,
·token("("),
·lst(
·layer_with_trailing_comma()·function_parameter,
·token(",")
)·function_parameters,
·token(")")
)
} >> {
·function_name(·function_parameters ··· (, ) {·function_parameter})
}

macro {
·chain(
·token(","),
·token(")")·paren
)
} >> {
··unvar(·paren)
}
12 changes: 12 additions & 0 deletions src/parsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Yay;

const LAYER_DELIMITERS_WITH_TRAILING_COMMA = [
',' => -3,
] + LAYER_DELIMITERS;

function layer_with_trailing_comma(array $delimiters = LAYER_DELIMITERS_WITH_TRAILING_COMMA) : Parser
{
return layer($delimiters);
}
13 changes: 13 additions & 0 deletions tests/SpecTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Pre\TrailingCommas;

use Pre\Testing\Runner;

class SpecTest extends Runner
{
protected function path(): string
{
return __DIR__ . "/specs";
}
}
14 changes: 14 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Yay;

// let's use a namespace trick, to make non-colliding variables predictable.

function md5($value)
{
return $value;
}

putenv("PRE_BASE_DIR=" . __DIR__ . "/..");

require __DIR__ . "/../vendor/autoload.php";
48 changes: 48 additions & 0 deletions tests/specs/trailing-commas.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--DESCRIPTION--

Test trailing commas

--GIVEN--

function foo(
$a = "hello",
$b = "world",
) {
// do something
}

$foo = function(
$a = "hello",
$b = "world",
) {
// do something
}

foo(
$a = "hello",
$b = "world",
)
foo(
"hello",
"world",
)

$foo(
"hello",
"world",
)

--EXPECT--

function foo($a = "hello", $b = "world") {
// do something
}

$foo = function($a = "hello", $b = "world") {
// do something
}

foo($a = "hello", $b = "world")
foo("hello", "world")

$foo("hello", "world")

0 comments on commit 411df51

Please sign in to comment.