]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Tidying up of linter code.
authorJoshua Spence <josh@joshuaspence.com>
Fri, 20 Jun 2014 08:26:44 +0000 (18:26 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Fri, 20 Jun 2014 08:26:44 +0000 (18:26 +1000)
Summary: Various tidying up of linting code.

Test Plan: `arc lint` and `arc unit` still pass.

Reviewers: chad, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9625

29 files changed:
src/lint/linter/ArcanistBaseXHPASTLinter.php
src/lint/linter/ArcanistCSSLintLinter.php
src/lint/linter/ArcanistCSharpLinter.php
src/lint/linter/ArcanistClosureLinter.php
src/lint/linter/ArcanistExternalLinter.php
src/lint/linter/ArcanistFilenameLinter.php
src/lint/linter/ArcanistFlake8Linter.php
src/lint/linter/ArcanistJSHintLinter.php
src/lint/linter/ArcanistLesscLinter.php
src/lint/linter/ArcanistLinter.php
src/lint/linter/ArcanistMergeConflictLinter.php
src/lint/linter/ArcanistPEP8Linter.php
src/lint/linter/ArcanistPhpcsLinter.php
src/lint/linter/ArcanistPhutilLibraryLinter.php
src/lint/linter/ArcanistPyLintLinter.php
src/lint/linter/ArcanistRubyLinter.php
src/lint/linter/ArcanistScriptAndRegexLinter.php
src/lint/linter/ArcanistSpellingLinter.php
src/lint/linter/ArcanistTextLinter.php
src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/ArcanistXMLLinter.php
src/lint/linter/__tests__/ArcanistLesscLinterTestCase.php
src/lint/linter/__tests__/ArcanistLinterTestCase.php
src/lint/linter/__tests__/ArcanistPEP8LinterTestCase.php
src/lint/linter/__tests__/ArcanistXMLLinterTestCase.php
src/lint/linter/reporter.js
src/lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php
src/lint/linter/xhpast/ArcanistXHPASTLintSwitchHook.php
src/lint/linter/xhpast/__tests__/ArcanistXHPASTLintNamingHookTestCase.php

index 80f76bbbf4cbd9b4f2144d3df5c44453daead4f9..a89ba9bc148d0b67414102413d802b761808ee66 100644 (file)
@@ -55,7 +55,6 @@ abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
 
 /* -(  Sharing Parse Trees  )------------------------------------------------ */
 
-
   /**
    * Get the linter object which is responsible for building parse trees.
    *
@@ -94,7 +93,6 @@ abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
     return $linter;
   }
 
-
   /**
    * Build futures on this linter, for use and to share with other linters.
    *
@@ -111,7 +109,6 @@ abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
     return array_select_keys($this->futures, $paths);
   }
 
-
   /**
    * Get a path's tree from the responsible linter.
    *
@@ -144,7 +141,6 @@ abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
     return $this->trees[$path];
   }
 
-
   /**
    * Get a path's parse exception from the responsible linter.
    *
@@ -160,5 +156,4 @@ abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
     return idx($this->exceptions, $path);
   }
 
-
 }
index a488ed346aedc1d39fb8dddea88602cc2b411af5..4c5873571ffc9afaaa7dbf61230e61650a1caf59 100644 (file)
@@ -14,8 +14,7 @@ final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
   }
 
   public function getInfoDescription() {
-    return pht(
-      'Use `csslint` to detect issues with CSS source files.');
+    return pht('Use `csslint` to detect issues with CSS source files.');
   }
 
   public function getLinterName() {
index 3301425345b07f46c940d5c89fd691de0a6006ac..a9b9a257ce58e07a728723c09e70545f3d068c7b 100644 (file)
@@ -129,8 +129,7 @@ final class ArcanistCSharpLinter extends ArcanistLinter {
     $this->loaded = true;
   }
 
-  public function lintPath($path) {
-  }
+  public function lintPath($path) {}
 
   public function willLintPaths(array $paths) {
     $this->loadEnvironment();
index 6cc21bba1127b54d093e7639f8b3385cd1090f5b..890973824ce56824d763d0cc4ce601da39df5344 100644 (file)
@@ -14,8 +14,7 @@ final class ArcanistClosureLinter extends ArcanistExternalLinter {
   }
 
   public function getInfoDescription() {
-    return pht(
-      'Uses Google\'s Closure Linter to check Javascript code.');
+    return pht("Uses Google's Closure Linter to check Javascript code.");
   }
 
   public function getLinterName() {
@@ -26,16 +25,13 @@ final class ArcanistClosureLinter extends ArcanistExternalLinter {
     return 'gjslint';
   }
 
-  protected function getDefaultMessageSeverity($code) {
-    return ArcanistLintSeverity::SEVERITY_ERROR;
-  }
-
   public function getDefaultBinary() {
     return 'gjslint';
   }
 
   public function getInstallInstructions() {
-    return pht('Install gJSLint using `sudo easy_install http://closure-linter'.
+    return pht(
+      'Install gJSLint using `sudo easy_install http://closure-linter'.
       '.googlecode.com/files/closure_linter-latest.tar.gz`');
   }
 
@@ -53,7 +49,7 @@ final class ArcanistClosureLinter extends ArcanistExternalLinter {
     $regex = '/^Line (\d+), (E:\d+): (.*)/';
     $severity_code = ArcanistLintSeverity::SEVERITY_ERROR;
 
-    $lines = explode("\n", $stdout);
+    $lines = phutil_split_lines($stdout, false);
 
     $messages = array();
     foreach ($lines as $line) {
@@ -79,4 +75,5 @@ final class ArcanistClosureLinter extends ArcanistExternalLinter {
 
     return $messages;
   }
+
 }
index ec889d8927bcda6325f602e4570e8dc961b0ba98..23b4da6c5c6de5e80e1411297f1d187ca7ec15ae 100644 (file)
@@ -17,7 +17,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
 
 /* -(  Interpreters, Binaries and Flags  )----------------------------------- */
 
-
   /**
    * Return the default binary name or binary path where the external linter
    * lives. This can either be a binary name which is expected to be installed
@@ -33,7 +32,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
    */
   abstract public function getDefaultBinary();
 
-
   /**
    * Return a human-readable string describing how to install the linter. This
    * is normally something like "Install such-and-such by running `npm install
@@ -44,7 +42,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
    */
   abstract public function getInstallInstructions();
 
-
   /**
    * Return true to continue when the external linter exits with an error code.
    * By default, linters which exit with an error code are assumed to have
@@ -62,7 +59,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return false;
   }
 
-
   /**
    * Return true to indicate that the external linter can read input from
    * stdin, rather than requiring a file. If this mode is supported, it is
@@ -93,7 +89,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return false;
   }
 
-
   /**
    * If the linter can read data over stdin, override
    * @{method:supportsReadDataFromStdin} and then optionally override this
@@ -108,7 +103,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return null;
   }
 
-
   /**
    * Provide mandatory, non-overridable flags to the linter. Generally these
    * are format flags, like `--format=xml`, which must always be given for
@@ -124,7 +118,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return array();
   }
 
-
   /**
    * Provide default, overridable flags to the linter. Generally these are
    * configuration flags which affect behavior but aren't critical. Flags
@@ -140,7 +133,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return array();
   }
 
-
   /**
    * Override default flags with custom flags. If not overridden, flags provided
    * by @{method:getDefaultFlags} are used.
@@ -154,7 +146,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return $this;
   }
 
-
   /**
    * Return the binary or script to execute. This method synthesizes defaults
    * and configuration. You can override the binary with @{method:setBinary}.
@@ -166,7 +157,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return coalesce($this->bin, $this->getDefaultBinary());
   }
 
-
   /**
    * Override the default binary with a new one.
    *
@@ -179,7 +169,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return $this;
   }
 
-
   /**
    * Return true if this linter should use an interpreter (like "python" or
    * "node") in addition to the script.
@@ -194,7 +183,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return false;
   }
 
-
   /**
    * Return the default interpreter, like "python" or "node". This method is
    * only invoked if @{method:shouldUseInterpreter} has been overridden to
@@ -207,7 +195,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     throw new Exception('Incomplete implementation!');
   }
 
-
   /**
    * Get the effective interpreter. This method synthesizes configuration and
    * defaults.
@@ -219,7 +206,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return coalesce($this->interpreter, $this->getDefaultInterpreter());
   }
 
-
   /**
    * Set the interpreter, overriding any default.
    *
@@ -235,7 +221,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
 
 /* -(  Parsing Linter Output  )---------------------------------------------- */
 
-
   /**
    * Parse the output of the external lint program into objects of class
    * @{class:ArcanistLintMessage} which `arc` can consume. Generally, this
@@ -260,7 +245,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
 
 /* -(  Executing the Linter  )----------------------------------------------- */
 
-
   /**
    * Check that the binary and interpreter (if applicable) exist, and throw
    * an exception with a message about how to install them if they do not.
@@ -315,7 +299,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     }
   }
 
-
   /**
    * Get the composed executable command, including the interpreter and binary
    * but without flags or paths. This can be used to execute `--version`
@@ -343,7 +326,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return $bin;
   }
 
-
   /**
    * Get the composed flags for the executable, including both mandatory and
    * configured flags.
@@ -381,7 +363,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     }
   }
 
-
   /**
    * Prepare the path to be added to the command string.
    *
@@ -533,7 +514,6 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
     return parent::setLinterConfigurationValue($key, $value);
   }
 
-
   /**
    * Map a configuration lint code to an `arc` lint code. Primarily, this is
    * intended for validation, but can also be used to normalize case or
index 59d38c0080e30869e91da73371ec5c78a204b5b0..e5ba19c582dbf9d28f03c3175bbfaa885f6cde74 100644 (file)
@@ -31,7 +31,7 @@ final class ArcanistFilenameLinter extends ArcanistLinter {
 
   public function getLintNameMap() {
     return array(
-      self::LINT_BAD_FILENAME   => pht('Bad Filename'),
+      self::LINT_BAD_FILENAME => pht('Bad Filename'),
     );
   }
 
index a910239271abf31cff98cdb9bf0101e5e544af4c..9ab99d7e8fe96a6e0dd1f40e34242a14ff46fc6c 100644 (file)
@@ -71,7 +71,7 @@ final class ArcanistFlake8Linter extends ArcanistExternalLinter {
   }
 
   protected function parseLinterOutput($path, $err, $stdout, $stderr) {
-    $lines = phutil_split_lines($stdout, $retain_endings = false);
+    $lines = phutil_split_lines($stdout, false);
 
     $messages = array();
     foreach ($lines as $line) {
index 89e4525911ce97f3f8de21c26db810f1a8327cf5..a3b4915536848d48f1974577c34b75dd7f4af62e 100644 (file)
@@ -17,8 +17,7 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
   }
 
   public function getInfoDescription() {
-    return pht(
-      'Use `jshint` to detect issues with Javascript source files.');
+    return pht('Use `jshint` to detect issues with Javascript source files.');
   }
 
   public function getLinterName() {
@@ -179,4 +178,5 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
 
     return $code;
   }
+
 }
index b754e1a94e3eea08c625ed7f5f0913255b6067f7..9e6647e16375aebe5e40cb164284220535a004c4 100644 (file)
@@ -51,8 +51,7 @@ final class ArcanistLesscLinter extends ArcanistExternalLinter {
       ),
       'lessc.strict-units' => array(
         'type' => 'optional bool',
-        'help' => pht(
-          'Enable strict handling of units in expressions.'),
+        'help' => pht('Enable strict handling of units in expressions.'),
       ),
     );
   }
@@ -195,4 +194,5 @@ final class ArcanistLesscLinter extends ArcanistExternalLinter {
 
     return $messages;
   }
+
 }
index 5c798ed39c7865f2e00e9b1300d0f9464081a28f..9001362d83d8210a8696356b7193744c3b4ef0aa 100644 (file)
@@ -28,7 +28,6 @@ abstract class ArcanistLinter {
 
 /*  -(  Human Readable Information  )---------------------------------------- */
 
-
   /**
    * Return an optional informative URI where humans can learn more about this
    * linter.
@@ -43,7 +42,6 @@ abstract class ArcanistLinter {
     return null;
   }
 
-
   /**
    * Return a brief human-readable description of the linter.
    *
@@ -56,7 +54,6 @@ abstract class ArcanistLinter {
     return null;
   }
 
-
   /**
    * Return a human-readable linter name.
    *
@@ -73,7 +70,6 @@ abstract class ArcanistLinter {
       get_class($this));
   }
 
-
   public function getLinterPriority() {
     return 1.0;
   }
@@ -264,10 +260,7 @@ abstract class ArcanistLinter {
     return $this->addLintMessage($message);
   }
 
-  final protected function raiseLintAtPath(
-    $code,
-    $desc) {
-
+  final protected function raiseLintAtPath($code, $desc) {
     return $this->raiseLintAtLine(null, null, $code, $desc, null, null);
   }
 
@@ -464,7 +457,6 @@ abstract class ArcanistLinter {
     return $code;
   }
 
-
   /**
    * Retrieve an old lint configuration value from `.arcconfig` or a similar
    * source.
@@ -477,7 +469,6 @@ abstract class ArcanistLinter {
    * @return  wild    Configured value, or default if no configuration exists.
    */
   final protected function getDeprecatedConfiguration($key, $default = null) {
-
     // If we're being called in a context without an engine (probably from
     // `arc linters`), just return the default value.
     if (!$this->engine) {
index f7092ff6e2ec6e2620664218733ed166b9b42ed3..021b456fa7e6bb844355e724a5801b148b73a2b5 100644 (file)
@@ -45,12 +45,6 @@ final class ArcanistMergeConflictLinter extends ArcanistLinter {
     }
   }
 
-  public function getLintSeverityMap() {
-    return array(
-      self::LINT_MERGECONFLICT => ArcanistLintSeverity::SEVERITY_ERROR,
-    );
-  }
-
   public function getLintNameMap() {
     return array(
       self::LINT_MERGECONFLICT => pht('Unresolved merge conflict'),
index 0b19006d809ed23f59ea8124e43bab49562d9f94..2d76e3f78452ebb6b45938392e3e2e80d88686c5 100644 (file)
@@ -75,7 +75,7 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
   }
 
   protected function parseLinterOutput($path, $err, $stdout, $stderr) {
-    $lines = phutil_split_lines($stdout, $retain_endings = false);
+    $lines = phutil_split_lines($stdout, false);
 
     $messages = array();
     foreach ($lines as $line) {
index 1dbb10a76304d68bb5fcbd95a7573bde431b2cf0..dccbc01b3a4868f3331b42939ac3a36e93f71941 100644 (file)
@@ -1,15 +1,7 @@
 <?php
 
 /**
- * Uses "PHP_CodeSniffer" to detect checkstyle errors in php code.
- * To use this linter, you must install PHP_CodeSniffer.
- * http://pear.php.net/package/PHP_CodeSniffer.
- *
- * Optional configurations in .arcconfig:
- *
- *   lint.phpcs.standard
- *   lint.phpcs.options
- *   lint.phpcs.bin
+ * Uses "PHP_CodeSniffer" to detect checkstyle errors in PHP code.
  *
  * @group linter
  */
@@ -50,6 +42,7 @@ final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
   public function getDefaultFlags() {
     $options = $this->getDeprecatedConfiguration('lint.phpcs.options', array());
     $standard = $this->getDeprecatedConfiguration('lint.phpcs.standard');
+
     if (!empty($standard)) {
       if (is_array($options)) {
         $options[] = '--standard='.$standard;
index bf94344f38be93f3c22eec9d58ebae7a24917a51..d9934dd05acc6118946a65b579e2dadd1e6c7f18 100644 (file)
@@ -10,9 +10,9 @@
  */
 final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
 
-  const LINT_UNKNOWN_SYMBOL               = 1;
-  const LINT_DUPLICATE_SYMBOL             = 2;
-  const LINT_ONE_CLASS_PER_FILE           = 3;
+  const LINT_UNKNOWN_SYMBOL      = 1;
+  const LINT_DUPLICATE_SYMBOL    = 2;
+  const LINT_ONE_CLASS_PER_FILE  = 3;
 
   public function getInfoName() {
     return 'Phutil Library Linter';
@@ -30,9 +30,9 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
 
   public function getLintNameMap() {
     return array(
-      self::LINT_UNKNOWN_SYMBOL         => 'Unknown Symbol',
-      self::LINT_DUPLICATE_SYMBOL       => 'Duplicate Symbol',
-      self::LINT_ONE_CLASS_PER_FILE     => 'One Class Per File',
+      self::LINT_UNKNOWN_SYMBOL     => 'Unknown Symbol',
+      self::LINT_DUPLICATE_SYMBOL   => 'Duplicate Symbol',
+      self::LINT_ONE_CLASS_PER_FILE => 'One Class Per File',
     );
   }
 
@@ -58,7 +58,7 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
     // the working copy.
 
     $arc_root = dirname(phutil_get_library_root('arcanist'));
-    $bin = "{$arc_root}/scripts/phutil_rebuild_map.php";
+    $bin = $arc_root.'/scripts/phutil_rebuild_map.php';
 
     $symbols = array();
     foreach ($libs as $lib) {
index 9ce9202d4d20659f1681a4126dee4dc6b12279e6..7c5538b12d9c91ce43a90f0e2f31d6d96a0a4091 100644 (file)
@@ -54,7 +54,6 @@
 final class ArcanistPyLintLinter extends ArcanistLinter {
 
   private function getMessageCodeSeverity($code) {
-
     $config = $this->getEngine()->getConfigurationManager();
 
     $error_regexp   =
@@ -148,9 +147,9 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
     if ($config_paths !== null) {
       foreach ($config_paths as $config_path) {
         if ($config_path !== null) {
-          $python_path[] =
-            Filesystem::resolvePath($config_path,
-                                    $working_copy->getProjectRoot());
+          $python_path[] = Filesystem::resolvePath(
+            $config_path,
+            $working_copy->getProjectRoot());
         }
       }
     }
@@ -181,8 +180,8 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
     $rcfile = $config->getConfigFromAnySource('lint.pylint.rcfile');
     if ($rcfile !== null) {
       $rcfile = Filesystem::resolvePath(
-                   $rcfile,
-                   $working_copy->getProjectRoot());
+        $rcfile,
+        $working_copy->getProjectRoot());
       $options[] = csprintf('--rcfile=%s', $rcfile);
     }
 
@@ -200,16 +199,12 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
   }
 
   private function getLinterVersion() {
-
     $pylint_bin = $this->getPyLintPath();
     $options = '--version';
 
-    list($stdout) = execx(
-      '%s %s',
-      $pylint_bin,
-      $options);
+    list($stdout) = execx('%s %s', $pylint_bin, $options);
 
-    $lines = explode("\n", $stdout);
+    $lines = phutil_split_lines($stdout, false);
     $matches = null;
 
     // If the version command didn't return anything or the regex didn't match
@@ -247,13 +242,12 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
       }
     }
 
-    $lines = explode("\n", $stdout);
+    $lines = phutil_split_lines($stdout, false);
     $messages = array();
     foreach ($lines as $line) {
       $matches = null;
-      if (!preg_match(
-              '/([A-Z]\d+): *(\d+)(?:|,\d*): *(.*)$/',
-              $line, $matches)) {
+      $regex = '/([A-Z]\d+): *(\d+)(?:|,\d*): *(.*)$/';
+      if (!preg_match($regex, $line, $matches)) {
         continue;
       }
       foreach ($matches as $key => $match) {
index 1d093733b80e9a29f9449c03bc12459c2651b562..278472209103ec519c89c49e5fe25847eb0d69aa 100644 (file)
@@ -64,12 +64,8 @@ final class ArcanistRubyLinter extends ArcanistExternalLinter {
     return array('-w', '-c');
   }
 
-  protected function getDefaultMessageSeverity($code) {
-    return ArcanistLintSeverity::SEVERITY_ERROR;
-  }
-
   protected function parseLinterOutput($path, $err, $stdout, $stderr) {
-    $lines = phutil_split_lines($stderr, $retain_endings = false);
+    $lines = phutil_split_lines($stderr, false);
 
     $messages = array();
     foreach ($lines as $line) {
index da4ebe1146d0dacdf420a0141f0e5ffed0533631..1c12ff0d846dd2ded1303c494692401ad83b7ba9 100644 (file)
@@ -159,7 +159,6 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
 
   private $output = array();
 
-
   public function getInfoName() {
     return pht('Script and Regex');
   }
@@ -196,7 +195,6 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     }
   }
 
-
   /**
    * Run the regex on the output of the script.
    *
@@ -247,13 +245,13 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
       list($line, $char) = $this->getMatchLineAndChar($match, $path);
 
       $dict = array(
-        'path'          => idx($match, 'file', $path),
-        'line'          => $line,
-        'char'          => $char,
-        'code'          => idx($match, 'code', $this->getLinterName()),
-        'severity'      => $this->getMatchSeverity($match),
-        'name'          => idx($match, 'name', 'Lint'),
-        'description'   => idx($match, 'message', 'Undefined Lint Message'),
+        'path'        => idx($match, 'file', $path),
+        'line'        => $line,
+        'char'        => $char,
+        'code'        => idx($match, 'code', $this->getLinterName()),
+        'severity'    => $this->getMatchSeverity($match),
+        'name'        => idx($match, 'name', 'Lint'),
+        'description' => idx($match, 'message', 'Undefined Lint Message'),
       );
 
       $original = idx($match, 'original');
@@ -274,7 +272,6 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
 
 /* -(  Linter Information  )------------------------------------------------- */
 
-
   /**
    * Return the short name of the linter.
    *
@@ -290,8 +287,8 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     return 'script-and-regex';
   }
 
-/* -(  Parsing Output  )----------------------------------------------------- */
 
+/* -(  Parsing Output  )----------------------------------------------------- */
 
   /**
    * Get the line and character of the message from the regex match.
@@ -315,7 +312,6 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     return array($line, $char);
   }
 
-
   /**
    * Map the regex matching groups to a message severity. We look for either
    * a nonempty severity name group like 'error', or a group called 'severity'
@@ -328,11 +324,11 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
    */
   private function getMatchSeverity(array $match) {
     $map = array(
-      'error'     => ArcanistLintSeverity::SEVERITY_ERROR,
-      'warning'   => ArcanistLintSeverity::SEVERITY_WARNING,
-      'autofix'   => ArcanistLintSeverity::SEVERITY_AUTOFIX,
-      'advice'    => ArcanistLintSeverity::SEVERITY_ADVICE,
-      'disabled'  => ArcanistLintSeverity::SEVERITY_DISABLED,
+      'error'    => ArcanistLintSeverity::SEVERITY_ERROR,
+      'warning'  => ArcanistLintSeverity::SEVERITY_WARNING,
+      'autofix'  => ArcanistLintSeverity::SEVERITY_AUTOFIX,
+      'advice'   => ArcanistLintSeverity::SEVERITY_ADVICE,
+      'disabled' => ArcanistLintSeverity::SEVERITY_DISABLED,
     );
 
     $severity_name = strtolower(idx($match, 'severity'));
@@ -340,8 +336,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     foreach ($map as $name => $severity) {
       if (!empty($match[$name])) {
         return $severity;
-      }
-      if ($severity_name == $name) {
+      } else if ($severity_name == $name) {
         return $severity;
       }
     }
@@ -352,7 +347,6 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
 
 /* -(  Validating Configuration  )------------------------------------------- */
 
-
   /**
    * Load, validate, and return the "script" configuration.
    *
@@ -379,7 +373,6 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     return $config;
   }
 
-
   /**
    * Load, validate, and return the "regex" configuration.
    *
index c04553bd65da87b8e07d6ceec4576d34e518b0bf..c96d24034f4f58ba19b318a33bd6cc8f03045d86 100644 (file)
@@ -56,14 +56,14 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
 
   public function getLintSeverityMap() {
     return array(
-      self::LINT_SPELLING_PICKY => ArcanistLintSeverity::SEVERITY_WARNING,
+      self::LINT_SPELLING_PICKY     => ArcanistLintSeverity::SEVERITY_WARNING,
       self::LINT_SPELLING_IMPORTANT => ArcanistLintSeverity::SEVERITY_ERROR,
     );
   }
 
   public function getLintNameMap() {
     return array(
-      self::LINT_SPELLING_PICKY => pht('Possible Spelling Mistake'),
+      self::LINT_SPELLING_PICKY     => pht('Possible Spelling Mistake'),
       self::LINT_SPELLING_IMPORTANT => pht('Possible Spelling Mistake'),
     );
   }
@@ -105,7 +105,7 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
       $this->raiseLintAtOffset(
         $next,
         $severity,
-        sprintf(
+        pht(
           "Possible spelling error. You wrote '%s', but did you mean '%s'?",
           $word,
           $correct_word),
@@ -132,7 +132,7 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
       $this->raiseLintAtOffset(
         $match[1],
         $severity,
-        sprintf(
+        pht(
           "Possible spelling error. You wrote '%s', but did you mean '%s'?",
           $word,
           $correct_word),
@@ -144,14 +144,13 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
   public static function fixLetterCase($string, $case) {
     if ($case == strtolower($case)) {
       return strtolower($string);
-    }
-    if ($case == strtoupper($case)) {
+    } else if ($case == strtoupper($case)) {
       return strtoupper($string);
-    }
-    if ($case == ucwords(strtolower($case))) {
+    } else if ($case == ucwords(strtolower($case))) {
       return ucwords(strtolower($string));
+    } else {
+      return null;
     }
-    return null;
   }
 
 }
index 5de9a618a2ac15a30593bd30751a8855e65039b4..11afc5c1ca88db21b9fc82924a6106bf1bdde318 100644 (file)
@@ -5,15 +5,15 @@
  */
 final class ArcanistTextLinter extends ArcanistLinter {
 
-  const LINT_DOS_NEWLINE            = 1;
-  const LINT_TAB_LITERAL            = 2;
-  const LINT_LINE_WRAP              = 3;
-  const LINT_EOF_NEWLINE            = 4;
-  const LINT_BAD_CHARSET            = 5;
-  const LINT_TRAILING_WHITESPACE    = 6;
-  const LINT_NO_COMMIT              = 7;
-  const LINT_BOF_WHITESPACE         = 8;
-  const LINT_EOF_WHITESPACE         = 9;
+  const LINT_DOS_NEWLINE          = 1;
+  const LINT_TAB_LITERAL          = 2;
+  const LINT_LINE_WRAP            = 3;
+  const LINT_EOF_NEWLINE          = 4;
+  const LINT_BAD_CHARSET          = 5;
+  const LINT_TRAILING_WHITESPACE  = 6;
+  const LINT_NO_COMMIT            = 7;
+  const LINT_BOF_WHITESPACE       = 8;
+  const LINT_EOF_WHITESPACE       = 9;
 
   private $maxLineLength = 80;
 
@@ -69,24 +69,24 @@ final class ArcanistTextLinter extends ArcanistLinter {
 
   public function getLintSeverityMap() {
     return array(
-      self::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_WARNING,
+      self::LINT_LINE_WRAP           => ArcanistLintSeverity::SEVERITY_WARNING,
       self::LINT_TRAILING_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX,
-      self::LINT_BOF_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX,
-      self::LINT_EOF_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX,
+      self::LINT_BOF_WHITESPACE      => ArcanistLintSeverity::SEVERITY_AUTOFIX,
+      self::LINT_EOF_WHITESPACE      => ArcanistLintSeverity::SEVERITY_AUTOFIX,
     );
   }
 
   public function getLintNameMap() {
     return array(
-      self::LINT_DOS_NEWLINE          => pht('DOS Newlines'),
-      self::LINT_TAB_LITERAL          => pht('Tab Literal'),
-      self::LINT_LINE_WRAP            => pht('Line Too Long'),
-      self::LINT_EOF_NEWLINE          => pht('File Does Not End in Newline'),
-      self::LINT_BAD_CHARSET          => pht('Bad Charset'),
-      self::LINT_TRAILING_WHITESPACE  => pht('Trailing Whitespace'),
-      self::LINT_NO_COMMIT            => pht('Explicit %s', '@no'.'commit'),
-      self::LINT_BOF_WHITESPACE       => pht('Leading Whitespace at BOF'),
-      self::LINT_EOF_WHITESPACE       => pht('Trailing Whitespace at EOF'),
+      self::LINT_DOS_NEWLINE         => pht('DOS Newlines'),
+      self::LINT_TAB_LITERAL         => pht('Tab Literal'),
+      self::LINT_LINE_WRAP           => pht('Line Too Long'),
+      self::LINT_EOF_NEWLINE         => pht('File Does Not End in Newline'),
+      self::LINT_BAD_CHARSET         => pht('Bad Charset'),
+      self::LINT_TRAILING_WHITESPACE => pht('Trailing Whitespace'),
+      self::LINT_NO_COMMIT           => pht('Explicit %s', '@no'.'commit'),
+      self::LINT_BOF_WHITESPACE      => pht('Leading Whitespace at BOF'),
+      self::LINT_EOF_WHITESPACE      => pht('Trailing Whitespace at EOF'),
     );
   }
 
index c7e4e1753e715d3bc780d9986f29e224355ac416..b09d50cbd77aa27e846eb9b1ac7b2a72a2f6d8ee 100644 (file)
@@ -174,7 +174,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
       ),
       'xhpast.php-version.windows' => array(
         'type' => 'optional string',
-        'help' => pht('PHP version to target on Windows.')
+        'help' => pht('PHP version to target on Windows.'),
       ),
     );
   }
index f67ef0b75d3a6eebeb2b13189fe5fe551cce8f8c..2410c0ccd52b51850bc35f8475a0f1fa18cc85b3 100644 (file)
@@ -70,4 +70,5 @@ final class ArcanistXMLLinter extends ArcanistLinter {
       $this->addLintMessage($message);
     }
   }
+
 }
index 089c72bda4b90b3a6ca9395388b46831545dd479..9303d3713fd24c02c709ed8ee883fd63a231b33b 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
-final class ArcanistLesscLinterTestCase
-  extends ArcanistArcanistLinterTestCase {
+final class ArcanistLesscLinterTestCase extends ArcanistArcanistLinterTestCase {
 
   public function testLesscLinter() {
     $this->executeTestsInDirectory(
index d94bc89d2c070ea7be7b1c53e874044f8e95e362..53c65f0f52caba0b2d121e70ea1106f4d3752724 100644 (file)
@@ -22,7 +22,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
       pht('Expected to find some .lint-test tests in directory %s!', $root));
   }
 
-  private function lintFile($file, $linter) {
+  private function lintFile($file, ArcanistLinter $linter) {
     $linter = clone $linter;
 
     $contents = Filesystem::readFile($file);
@@ -38,14 +38,10 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
 
     $basename = basename($file);
 
-    if ($config) {
-      $config = json_decode($config, true);
-      if (!is_array($config)) {
-        throw new Exception(
-          "Invalid configuration in test '{$basename}', not valid JSON.");
-      }
-    } else {
-      $config = array();
+    $config = phutil_json_decode($config);
+    if (!is_array($config)) {
+      throw new Exception(
+        "Invalid configuration in test '{$basename}', not valid JSON.");
     }
 
     PhutilTypeSpec::checkMap(
@@ -62,8 +58,8 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
     $messages = null;
     $exception_message = false;
     $caught_exception = false;
-    try {
 
+    try {
       $tmp = new TempFile($basename);
       Filesystem::writeFile($tmp, $data);
       $full_path = (string)$tmp;
@@ -112,7 +108,6 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
       $result = reset($results);
       $patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
       $after_lint = $patcher->getModifiedFileContent();
-
     } catch (ArcanistPhutilTestTerminatedException $ex) {
       throw $ex;
     } catch (Exception $exception) {
@@ -133,19 +128,16 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
                            $exception->getTraceAsString();
     }
 
-    switch ($basename) {
-      default:
-        $this->assertEqual(false, $caught_exception, $exception_message);
-        $this->compareLint($basename, $expect, $result);
-        $this->compareTransform($xform, $after_lint);
-        break;
-    }
+    $this->assertEqual(false, $caught_exception, $exception_message);
+    $this->compareLint($basename, $expect, $result);
+    $this->compareTransform($xform, $after_lint);
   }
 
-  private function compareLint($file, $expect, $result) {
+  private function compareLint($file, $expect, ArcanistLintResult $result) {
     $seen = array();
     $raised = array();
     $message_map = array();
+
     foreach ($result->getMessages() as $message) {
       $sev = $message->getSeverity();
       $line = $message->getLine();
@@ -195,7 +187,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
     }
   }
 
-  protected function compareTransform($expected, $actual) {
+  private function compareTransform($expected, $actual) {
     if (!strlen($expected)) {
       return;
     }
index 184e4879d19b27a25386e0a900b07e2277d949e1..2a055bc89311beb5682a8890e9abf7507ed2897d 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
-final class ArcanistPEP8LinterTestCase
-  extends ArcanistArcanistLinterTestCase {
+final class ArcanistPEP8LinterTestCase extends ArcanistArcanistLinterTestCase {
 
   public function testPEP8Linter() {
     $this->executeTestsInDirectory(
index 5d764d6987a4c513c3513ee904ffa5afb8baedd2..d9e04a875895bf16885382f4780e9883c6d4a510 100644 (file)
@@ -5,9 +5,11 @@
  * https://git.gnome.org/browse/libxml2/tree/test.
  */
 final class ArcanistXMLLinterTestCase extends ArcanistArcanistLinterTestCase {
+
   public function testXMLLint() {
     $this->executeTestsInDirectory(
       dirname(__FILE__).'/xml/',
       new ArcanistXMLLinter());
   }
+
 }
index e2d4ff5a20326c7fbaf7e8528111e0f9db9c59e4..42d0d07b82dd1e015d0f1cf52da315d433b32890 100644 (file)
@@ -1,19 +1,19 @@
 module.exports = {
-    reporter: function (results) {
-        var report = [];
+  reporter: function (results) {
+    var report = [];
 
-        results.forEach(function (result) {
-            var error = result.error;
-            report.push({
-                'file'    : result.file,
-                'line'    : error.line,
-                'col'     : error.character,
-                'reason'  : error.reason,
-                'code'    : error.code,
-                'evidence': error.evidence,
-            });
-        });
+    results.forEach(function (result) {
+      var error = result.error;
+      report.push({
+        'file'    : result.file,
+        'line'    : error.line,
+        'col'     : error.character,
+        'reason'  : error.reason,
+        'code'    : error.code,
+        'evidence': error.evidence,
+      });
+    });
 
-        process.stdout.write(JSON.stringify(report));
-    }
+    process.stdout.write(JSON.stringify(report));
+  }
 };
index f53addde4499e1a67f590cae4d54be5db83feef2..9e70e6b4e9884cc529a0febaa5a05f996f543a75 100644 (file)
@@ -1,9 +1,8 @@
 <?php
 
 /**
- * You can extend this class and set ##"lint.xhpast.naminghook"## in your
- * ##.arcconfig## to have an opportunity to override lint results for symbol
- * names.
+ * You can extend this class and set `xhpast.naminghook` in your `.arclint` to
+ * have an opportunity to override lint results for symbol names.
  *
  * @task override   Overriding Symbol Name Lint Messages
  * @task util       Name Utilities
@@ -16,7 +15,6 @@ abstract class ArcanistXHPASTLintNamingHook {
 
 /* -(  Internals  )---------------------------------------------------------- */
 
-
   /**
    * The constructor is final because @{class:ArcanistXHPASTLinter} is
    * responsible for hook instantiation.
@@ -31,7 +29,6 @@ abstract class ArcanistXHPASTLintNamingHook {
 
 /* -(  Overriding Symbol Name Lint Messages  )------------------------------- */
 
-
   /**
    * Callback invoked for each symbol, which can override the default
    * determination of name validity or accept it by returning $default. The
@@ -63,7 +60,6 @@ abstract class ArcanistXHPASTLintNamingHook {
 
 /* -(  Name Utilities  )----------------------------------------------------- */
 
-
   /**
    * Returns true if a symbol name is UpperCamelCase.
    *
@@ -75,7 +71,6 @@ abstract class ArcanistXHPASTLintNamingHook {
     return preg_match('/^[A-Z][A-Za-z0-9]*$/', $symbol);
   }
 
-
   /**
    * Returns true if a symbol name is lowerCamelCase.
    *
@@ -87,7 +82,6 @@ abstract class ArcanistXHPASTLintNamingHook {
     return preg_match('/^[a-z][A-Za-z0-9]*$/', $symbol);
   }
 
-
   /**
    * Returns true if a symbol name is UPPERCASE_WITH_UNDERSCORES.
    *
@@ -99,7 +93,6 @@ abstract class ArcanistXHPASTLintNamingHook {
     return preg_match('/^[A-Z0-9_]+$/', $symbol);
   }
 
-
   /**
    * Returns true if a symbol name is lowercase_with_underscores.
    *
@@ -111,7 +104,6 @@ abstract class ArcanistXHPASTLintNamingHook {
     return preg_match('/^[a-z0-9_]+$/', $symbol);
   }
 
-
   /**
    * Strip non-name components from PHP function symbols. Notably, this discards
    * the "__" magic-method signifier, to make a symbol appropriate for testing
@@ -127,7 +119,6 @@ abstract class ArcanistXHPASTLintNamingHook {
     return preg_replace('/^__/', '', $symbol);
   }
 
-
   /**
    * Strip non-name components from PHP variable symbols. Notably, this discards
    * the "$", to make a symbol appropriate for testing with methods like
index b7e4c339add83c95daeaa20cd625616d6a2e369e..e5a82ea10677b0c6b66956054d97ce70cad20e4c 100644 (file)
@@ -1,9 +1,8 @@
 <?php
 
 /**
- * You can extend this class and set `lint.xhpast.switchhook` in your
- * `.arcconfig` to have an opportunity to override results for linting `switch`
- * statements.
+ * You can extend this class and set `xhpast.switchhook` in your `.arclint`
+ * to have an opportunity to override results for linting `switch` statements.
  *
  * @group lint
  */
index f3b0a0945e5f6570fbf4f9d88a2dd711f35e793a..a3f6b28001cde57782995d0d92cc175aeefd41ef 100644 (file)
@@ -5,26 +5,25 @@
  *
  * @group testcase
  */
-final class ArcanistXHPASTLintNamingHookTestCase
-  extends ArcanistTestCase {
+final class ArcanistXHPASTLintNamingHookTestCase extends ArcanistTestCase {
 
   public function testCaseUtilities() {
     $tests = array(
-      'UpperCamelCase'                    => array(1, 0, 0, 0),
-      'UpperCamelCaseROFL'                => array(1, 0, 0, 0),
+      'UpperCamelCase'                   => array(1, 0, 0, 0),
+      'UpperCamelCaseROFL'               => array(1, 0, 0, 0),
 
-      'lowerCamelCase'                    => array(0, 1, 0, 0),
-      'lowerCamelCaseROFL'                => array(0, 1, 0, 0),
+      'lowerCamelCase'                   => array(0, 1, 0, 0),
+      'lowerCamelCaseROFL'               => array(0, 1, 0, 0),
 
-      'UPPERCASE_WITH_UNDERSCORES'        => array(0, 0, 1, 0),
-      '_UPPERCASE_WITH_UNDERSCORES_'      => array(0, 0, 1, 0),
-      '__UPPERCASE__WITH__UNDERSCORES__'  => array(0, 0, 1, 0),
+      'UPPERCASE_WITH_UNDERSCORES'       => array(0, 0, 1, 0),
+      '_UPPERCASE_WITH_UNDERSCORES_'     => array(0, 0, 1, 0),
+      '__UPPERCASE__WITH__UNDERSCORES__' => array(0, 0, 1, 0),
 
-      'lowercase_with_underscores'        => array(0, 0, 0, 1),
-      '_lowercase_with_underscores_'      => array(0, 0, 0, 1),
-      '__lowercase__with__underscores__'  => array(0, 0, 0, 1),
+      'lowercase_with_underscores'       => array(0, 0, 0, 1),
+      '_lowercase_with_underscores_'     => array(0, 0, 0, 1),
+      '__lowercase__with__underscores__' => array(0, 0, 0, 1),
 
-      'mixedCASE_NoNsEnSe'                => array(0, 0, 0, 0),
+      'mixedCASE_NoNsEnSe'               => array(0, 0, 0, 0),
     );
 
     foreach ($tests as $test => $expect) {