Skip to content

Commit

Permalink
Add default Editorconfig (#182)
Browse files Browse the repository at this point in the history
https://editorconfig.org/
This standard file inscructs text editors about the whitespace rules to use in any given project, so that contributors will automatically use the correct convention.
I could see for instance that #168 introduced a mix of spaces and tabs
  • Loading branch information
Alkarex authored Aug 17, 2022
1 parent 626201d commit 972d4ec
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# http://EditorConfig.org

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.json]
indent_style = tab

[*.md]
indent_size = 4
indent_style = tab

[*.php]
indent_style = tab

[*.xml]
indent_style = tab

[*.yml]
indent_size = 2
indent_style = space
2 changes: 1 addition & 1 deletion src/CssXPathException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

use RuntimeException;

class CssXPathException extends RuntimeException {}
class CssXPathException extends RuntimeException {}
2 changes: 1 addition & 1 deletion src/NotYetImplementedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
namespace Gt\CssXPath;

class NotYetImplementedException extends CssXPathException {}
class NotYetImplementedException extends CssXPathException {}
18 changes: 9 additions & 9 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function convertSingleSelector(string $css):string {
$thread = array_values($thread);

$xpath = [$this->prefix];
$hasElement = false;
$hasElement = false;
foreach($thread as $threadKey => $currentThreadItem) {
$next = isset($thread[$threadKey + 1])
? $thread[$threadKey + 1]
Expand All @@ -71,7 +71,7 @@ protected function convertSingleSelector(string $css):string {
case "star":
case "element":
$xpath []= $currentThreadItem['content'];
$hasElement = true;
$hasElement = true;
break;

case "pseudo":
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function convertSingleSelector(string $css):string {

case "child":
array_push($xpath, "/");
$hasElement = false;
$hasElement = false;
break;

case "id":
Expand All @@ -170,31 +170,31 @@ protected function convertSingleSelector(string $css):string {
($hasElement ? '' : '*')
. "[@id='{$currentThreadItem['content']}']"
);
$hasElement = true;
$hasElement = true;
break;

case "class":
// https://devhints.io/xpath#class-check
array_push(
$xpath,
($hasElement ? '' : '*')
($hasElement ? '' : '*')
. "[contains(concat(' ',normalize-space(@class),' '),' {$currentThreadItem['content']} ')]"
);
$hasElement = true;
$hasElement = true;
break;

case "sibling":
array_push(
$xpath,
"/following-sibling::*[1]/self::"
);
$hasElement = false;
$hasElement = false;
break;

case "attribute":
if(!$hasElement) {
array_push($xpath, "*");
$hasElement = true;
$hasElement = true;
}

/** @var null|array<int, array<string, string>> $detail */
Expand Down Expand Up @@ -263,7 +263,7 @@ protected function convertSingleSelector(string $css):string {

case "descendant":
array_push($xpath, "//");
$hasElement = false;
$hasElement = false;
break;
}
}
Expand Down
38 changes: 19 additions & 19 deletions test/phpunit/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class Helper {
<span>Site logo</span>
</a>
</h1>
<nav class="c-menu main-selection">
<input type="checkbox" id="toggle-menu" />
<label for="toggle-menu">
<span>Menu</span>
</label>
<ul>
<li>
<a href="/">Home</a>
Expand All @@ -58,7 +58,7 @@ class Helper {
<main>
<p>I'm a paragraph, but I'm not part of the article.</p>
<article>
<header>
<h1>
Expand Down Expand Up @@ -111,24 +111,24 @@ class Helper {
<label>
<span>From:</span>
<select name="from">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</label>
<label>
<span>To:</span>
<select name="to">
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
</label>
</form>
Expand All @@ -138,7 +138,7 @@ class Helper {
<!doctype html>
<form method="post">
<p>Please select and of the following:</p>
<label>
<input type="checkbox" name="choice[]" value="1" />
<span>Choice 1</span>
Expand All @@ -151,12 +151,12 @@ class Helper {
<input type="checkbox" name="choice[]" value="3" />
<span>Choice 3</span>
</label>
<button>Submit</button>
</form>
HTML;

const HTML_SELECTORS = <<<HTML
const HTML_SELECTORS = <<<HTML
<!doctype html>
<html>
<head>
Expand Down

0 comments on commit 972d4ec

Please sign in to comment.