Socket
Socket
Sign inDemoInstall

tslint-loader

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tslint-loader - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

.editorconfig

36

formatters/customFormatter.js
var Lint = require("tslint/lib/lint");
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Formatter = (function (_super) {
__extends(Formatter, _super);
function Formatter() {
_super.apply(this, arguments);
}
Formatter.prototype.format = function (failures) {
var outputLines = failures.map(function (failure) {
var failureString = failure.getFailure();
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var positionTuple = "[" + (lineAndCharacter.line + 1) + ", " + (lineAndCharacter.character + 1) + "]";
return positionTuple + ": " + failureString;
});
return outputLines.join("\n") + "\n";
};
return Formatter;
__extends(Formatter, _super);
function Formatter() {
_super.apply(this, arguments);
}
Formatter.prototype.format = function (failures) {
var outputLines = failures.map(function (failure) {
var failureString = failure.getFailure();
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var positionTuple = "[" + (lineAndCharacter.line + 1) + ", " + (lineAndCharacter.character + 1) + "]";
return positionTuple + ": " + failureString;
});
return outputLines.join("\n") + "\n";
};
return Formatter;
})(Lint.Formatters.AbstractFormatter);
exports.Formatter = Formatter;
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author William Buchwalter
based on jshint-loader by Tobias Koppers
MIT License http://www.opensource.org/licenses/mit-license.php
Author William Buchwalter
based on jshint-loader by Tobias Koppers
*/

@@ -12,51 +12,59 @@ var Linter = require("tslint");

var typescript = require("typescript");
var mkdirp = require("mkdirp");
var rimraf = require("rimraf");
function loadRelativeConfig() {
var options = {
formatter: "custom",
formattersDirectory: 'node_modules/tslint-loader/formatters/',
configuration: {}
};
var configPath = locateConfigFile("tslint.json", path.dirname(this.resourcePath));
if(typeof configPath == "string") {
this.addDependency(configPath);
var file = fs.readFileSync(configPath, "utf8");
options.configuration = JSON.parse(stripJsonComments(file));
}
return options;
var options = {
formatter: "custom",
formattersDirectory: 'node_modules/tslint-loader/formatters/',
configuration: {}
};
var configPath = locateConfigFile("tslint.json", path.dirname(this.resourcePath));
if(typeof configPath == "string") {
this.addDependency(configPath);
var file = fs.readFileSync(configPath, "utf8");
options.configuration = JSON.parse(stripJsonComments(file));
}
return options;
}
function locateConfigFile(filename, startingPath) {
var filePath = path.join(startingPath, filename);
if(typescript.sys.fileExists(filePath)){
return filePath;
}
var parentPath = path.dirname(startingPath);
if(parentPath === startingPath)
return undefined;
return locateConfigFile(filename,parentPath);
var filePath = path.join(startingPath, filename);
if(typescript.sys.fileExists(filePath)){
return filePath;
}
var parentPath = path.dirname(startingPath);
if(parentPath === startingPath)
return undefined;
return locateConfigFile(filename,parentPath);
}
function lint(input, options) {
//Override options in tslint.json by those passed to the compiler
if(this.options.tslint) {
merge(options, this.options.tslint);
}
function lint(input, options) {
//Override options in tslint.json by those passed to the compiler
if(this.options.tslint) {
merge(options, this.options.tslint);
}
//Override options in tslint.json by those passed to the loader as a query string
var query = loaderUtils.parseQuery(this.query);
merge(options, query);
var linter = new Linter(this.resourcePath, input, options);
var result = linter.lint();
var emitter = options.emitErrors ? this.emitError : this.emitWarning;
report(result, emitter, options.failOnHint);
//Override options in tslint.json by those passed to the loader as a query string
var query = loaderUtils.parseQuery(this.query);
merge(options, query);
var linter = new Linter(this.resourcePath, input, options);
var result = linter.lint();
var emitter = options.emitErrors ? this.emitError : this.emitWarning;
report(result, emitter, options.failOnHint, options.fileOutput);
}
function report(result, emitter, failOnHint) {
if(result.failureCount === 0) return;
emitter(result.output);
function report(result, emitter, failOnHint, fileOutputOpts) {
if(result.failureCount === 0) return;
emitter(result.output);
if(fileOutputOpts && fileOutputOpts.dir) {
writeToFile(fileOutputOpts, result);
}
if(failOnHint) {

@@ -67,2 +75,36 @@ throw new Error("Compilation failed due to tslint errors.");

var cleaned = false;
function writeToFile(fileOutputOpts, result) {
if(fileOutputOpts.clean === true && cleaned === false) {
rimraf.sync(fileOutputOpts.dir);
cleaned = true;
}
if(result.failures.length) {
mkdirp.sync(fileOutputOpts.dir);
var relativePath = path.relative("./", result.failures[0].fileName);
var targetPath = path.join(fileOutputOpts.dir, path.dirname(relativePath));
mkdirp.sync(targetPath);
var extension = fileOutputOpts.ext || "txt";
var targetFilePath = path.join(fileOutputOpts.dir, relativePath + "." + extension);
var contents = result.output;
if(fileOutputOpts.header) {
contents = fileOutputOpts.header + contents;
}
if(fileOutputOpts.footer) {
contents = contents + fileOutputOpts.footer;
}
fs.writeFileSync(targetFilePath, contents);
}
}
/* Merges two (or more) objects,

@@ -75,3 +117,3 @@ giving the last one precedence */

for (var property in source) {
for (var property in source) {
if ( source.hasOwnProperty(property) ) {

@@ -92,13 +134,13 @@ var sourceProperty = source[ property ];

return target;
};
}
module.exports = function(input, map) {
this.cacheable && this.cacheable();
var callback = this.async();
this.cacheable && this.cacheable();
var callback = this.async();
var config = loadRelativeConfig.call(this);
lint.call(this, input, config);
callback(null, input, map);
}
var config = loadRelativeConfig.call(this);
lint.call(this, input, config);
callback(null, input, map);
};
{
"name": "tslint-loader",
"version": "2.0.0",
"version": "2.1.0",
"description": "tslint loader for webpack",

@@ -31,4 +31,6 @@ "main": "index.js",

"loader-utils": "^0.2.7",
"mkdirp": "^0.5.1",
"rimraf": "^2.4.4",
"strip-json-comments": "^1.0.2"
}
}

@@ -9,13 +9,13 @@ # tslint loader for webpack

module.exports = {
module: {
preLoaders: [
{
test: /\.ts$/,
loader: "tslint"
}
]
},
// more options in the optional tslint object
tslint: {
configuration: {
module: {
preLoaders: [
{
test: /\.ts$/,
loader: "tslint"
}
]
},
// more options in the optional tslint object
tslint: {
configuration: {
rules: {

@@ -26,17 +26,38 @@ quotemark: [true, "double"]

// tslint errors are displayed by default as warnings
// set emitErrors to true to display them as errors
emitErrors: false,
// tslint errors are displayed by default as warnings
// set emitErrors to true to display them as errors
emitErrors: false,
// tslint does not interrupt the compilation by default
// if you want any file with tslint errors to fail
// set failOnHint to true
failOnHint: true,
// tslint does not interrupt the compilation by default
// if you want any file with tslint errors to fail
// set failOnHint to true
failOnHint: true,
// name of your formatter (optional)
formatter: "yourformatter",
// name of your formatter (optional)
formatter: "yourformatter",
// path to directory containing formatter (optional)
formattersDirectory: "node_modules/tslint-loader/formatters/"
}
// path to directory containing formatter (optional)
formattersDirectory: "node_modules/tslint-loader/formatters/"
// These options are useful if you want to save output to files
// for your continuous integration server
fileOutput: {
// The directory where each file's report is saved
dir: "./foo/",
// The extension to use for each report's filename. Defaults to "txt"
ext: "xml",
// If true, all files are removed from the report directory at the beginning of run
clean: true,
// A string to include at the top of every report file.
// Useful for some report formats.
header: "<?xml version="1.0" encoding="utf-8"?>\n<checkstyle version="5.7">",
// A string to include at the bottom of every report file.
// Useful for some report formats.
footer: "</checkstyle>"
}
}
}

@@ -43,0 +64,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc