<commit_before>package com.pablissimo.sonar;

import java.io.File;

import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.issue.Issuable;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;

import com.pablissimo.sonar.model.TsLintIssue;

public class TsLintSensor implements Sensor {
  	private FileSystem fileSystem;
  	private FilePredicates filePredicates;
  	private ResourcePerspectives perspectives;
  
	public TsLintSensor(FileSystem fileSystem, ResourcePerspectives perspectives) {
		this.fileSystem = fileSystem;
		this.filePredicates = fileSystem.predicates();
		this.perspectives = perspectives;
	}
	
	public boolean shouldExecuteOnProject(Project project) {
		boolean toReturn = hasFilesToAnalyze();
		
		return toReturn;
	}
	
	private boolean hasFilesToAnalyze() {
		return fileSystem.files(this.filePredicates.hasLanguage("ts")).iterator().hasNext();
	}

	public void analyse(Project project, SensorContext context) {
		TsLintExecutor executor = new TsLintExecutor();
		TsLintParser parser = new TsLintParser();
		
		for (File file : fileSystem.files(this.filePredicates.hasLanguage("ts"))) {
			Resource resource = org.sonar.api.resources.File.fromIOFile(file, project);
			Issuable issuable = perspectives.as(Issuable.class, resource);
			String jsonResult = executor.execute("C:\\Program Files (x86)\\nodejs\\node.exe", "C:\\temp\\tslint.json", file.getAbsolutePath());
			
			TsLintIssue[] issues = parser.parse(jsonResult);
			
			if (issues != null) {
				for (TsLintIssue issue : issues) {
					issuable.addIssue
					(
						issuable
							.newIssueBuilder()
							.line(issue.getStartPosition().getLine())
							.message(issue.getFailure())
							.ruleKey(RuleKey.of("tslint", issue.getRuleName()))
							.build()
					);				
				}
			}
		}
	}
}
<commit_msg>Fixing TsLint line references being off by one<commit_after>package com.pablissimo.sonar;

import java.io.File;

import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.issue.Issuable;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;

import com.pablissimo.sonar.model.TsLintIssue;

public class TsLintSensor implements Sensor {
  	private FileSystem fileSystem;
  	private FilePredicates filePredicates;
  	private ResourcePerspectives perspectives;
  
	public TsLintSensor(FileSystem fileSystem, ResourcePerspectives perspectives) {
		this.fileSystem = fileSystem;
		this.filePredicates = fileSystem.predicates();
		this.perspectives = perspectives;
	}
	
	public boolean shouldExecuteOnProject(Project project) {
		boolean toReturn = hasFilesToAnalyze();
		
		return toReturn;
	}
	
	private boolean hasFilesToAnalyze() {
		return fileSystem.files(this.filePredicates.hasLanguage("ts")).iterator().hasNext();
	}

	public void analyse(Project project, SensorContext context) {
		TsLintExecutor executor = new TsLintExecutor();
		TsLintParser parser = new TsLintParser();
		
		for (File file : fileSystem.files(this.filePredicates.hasLanguage("ts"))) {
			Resource resource = org.sonar.api.resources.File.fromIOFile(file, project);
			Issuable issuable = perspectives.as(Issuable.class, resource);
			String jsonResult = executor.execute("C:\\Program Files (x86)\\nodejs\\node.exe", "C:\\temp\\tslint.json", file.getAbsolutePath());
			
			TsLintIssue[] issues = parser.parse(jsonResult);
			
			if (issues != null) {
				for (TsLintIssue issue : issues) {
					issuable.addIssue
					(
						issuable
							.newIssueBuilder()
							.line(issue.getStartPosition().getLine() + 1)
							.message(issue.getFailure())
							.ruleKey(RuleKey.of("tslint", issue.getRuleName()))
							.build()
					);				
				}
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.11754684838160136, 'fraction_numerical': 0.0012168410805548796, 'mean_word_length': 4.269230769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7145589', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1287, 'n_words': 236}