Ticket #216: jslint.diff
| File jslint.diff, 4.3 kB (added by dthomas, 7 months ago) |
|---|
-
JslLintTask.php
old new 33 33 protected $file; // the source file (from xml attribute) 34 34 protected $filesets = array(); // all fileset objects assigned to this task 35 35 36 protected $showWarnings = true; 36 37 protected $haltOnFailure = false; 37 38 protected $hasErrors = false; 38 39 private $badFiles = array(); 39 40 40 41 /** 42 * Sets the flag if warnings should be shown 43 * @param boolean $show 44 */ 45 public function setShowWarnings($show) { 46 $this->showWarnings = StringHelper::booleanValue($show); 47 } 48 49 /** 41 50 * The haltonfailure property 42 51 * @param boolean $aValue 43 52 */ … … 99 108 exec('jsl', $output); 100 109 if (!preg_match('/JavaScript\sLint/', implode('', $output))) throw new BuildException('Javascript Lint not found'); 101 110 102 $command = 'jsl - process ';111 $command = 'jsl -output-format file:__FILE__;line:__LINE__;message:__ERROR__ -process '; 103 112 104 113 if(file_exists($file)) 105 114 { 106 115 if(is_readable($file)) 107 116 { 108 $message = array();109 exec($command.'"'.$file.'"', $message );117 $messages = array(); 118 exec($command.'"'.$file.'"', $messages); 110 119 111 $summary = $message [sizeof($message) - 1];120 $summary = $messages[sizeof($messages) - 1]; 112 121 113 preg_match('/ ^(.*)\serror/', $summary, $matches);114 $error s = $matches[0];122 preg_match('/(\d+)\serror/', $summary, $matches); 123 $errorCount = $matches[1]; 115 124 116 preg_match('/ ^(.*)\swarning/', $summary, $matches);117 $warning s = $matches[0];125 preg_match('/(\d+)\swarning/', $summary, $matches); 126 $warningCount = $matches[1]; 118 127 119 if(0 != $warnings) 128 $errors = array(); 129 $warnings = array(); 130 if ($errorCount > 0 || $warningCount > 0) { 131 $last = false; 132 foreach ($messages as $message) { 133 $matches = array(); 134 if (preg_match('/^(\.*)\^$/', $message)) { 135 $column = strlen($message); 136 if ($last == 'error') { 137 $errors[count($errors) - 1]['column'] = $column; 138 } else if ($last == 'warning') { 139 $warnings[count($warnings) - 1]['column'] = $column; 140 } 141 $last = false; 142 } 143 if (!preg_match('/^file:(.+);line:(\d+);message:(.+)$/', $message, $matches)) continue; 144 $msg = $matches[3]; 145 $data = array('filename' => $matches[1], 'line' => $matches[2], 'message' => $msg); 146 if (preg_match('/^.*error:.+$/i', $msg)) { 147 $errors[] = $data; 148 $last = 'error'; 149 } else if (preg_match('/^.*warning:.+$/i', $msg)) { 150 $warnings[] = $data; 151 $last = 'warning'; 152 } 153 } 154 } 155 156 if($this->showWarnings && $warningCount > 0) 120 157 { 121 $this->log($file . ': ' . $warnings . ' warnings detected', Project::MSG_INFO); 158 $this->log($file . ': ' . $warningCount . ' warnings detected', Project::MSG_WARN); 159 foreach ($warnings as $warning) { 160 $this->log('- line ' . $warning['line'] . (isset($warning['column']) ? ' column ' . $warning['column'] : '') . ': ' . $warning['message'], Project::MSG_WARN); 161 } 122 162 } 123 163 124 if( 0 != $errors)164 if($errorCount > 0) 125 165 { 126 $this->log($file . ': ' . $errors . ' errors detected', Project::MSG_ERR); 166 $this->log($file . ': ' . $errorCount . ' errors detected', Project::MSG_ERR); 167 foreach ($errors as $error) { 168 $this->log('- line ' . $error['line'] . (isset($error['column']) ? ' column ' . $error['column'] : '') . ': ' . $error['message'], Project::MSG_ERR); 169 } 127 170 $this->badFiles[] = $file; 128 171 $this->hasErrors = true; 129 } else {172 } else if (!$this->showWarnings || $warningCount == 0) { 130 173 $this->log($file . ': No syntax errors detected', Project::MSG_INFO); 131 174 } 132 175 } else {
