This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
259 changed files
with
14,650 additions
and
5,268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require("./tslint-cli"); | ||
require("../lib/tslint-cli"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function findConfiguration(configFile: string, inputFileLocation: string): any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2013 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var findup = require("findup-sync"); | ||
var CONFIG_FILENAME = "tslint.json"; | ||
var DEFAULT_CONFIG = { | ||
"rules": { | ||
"curly": true, | ||
"indent": [true, 4], | ||
"no-duplicate-key": true, | ||
"no-duplicate-variable": true, | ||
"no-empty": true, | ||
"no-eval": true, | ||
"no-trailing-whitespace": true, | ||
"no-unreachable": true, | ||
"no-use-before-declare": true, | ||
"quotemark": [true, "double"], | ||
"semicolon": true | ||
} | ||
}; | ||
function findConfiguration(configFile, inputFileLocation) { | ||
if (configFile) { | ||
return JSON.parse(fs.readFileSync(configFile, "utf8")); | ||
} | ||
// first look for package.json from input file location | ||
configFile = findup("package.json", { cwd: inputFileLocation, nocase: true }); | ||
if (configFile) { | ||
var content = require(configFile); | ||
if (content.tslintConfig) { | ||
return content.tslintConfig; | ||
} | ||
} | ||
// next look for tslint.json | ||
var homeDir = getHomeDir(); | ||
if (!homeDir) { | ||
return undefined; | ||
} | ||
var defaultPath = path.join(homeDir, CONFIG_FILENAME); | ||
configFile = findup(CONFIG_FILENAME, { cwd: inputFileLocation, nocase: true }) || defaultPath; | ||
if (fs.existsSync(configFile)) { | ||
return JSON.parse(fs.readFileSync(configFile, "utf8")); | ||
} | ||
else { | ||
return DEFAULT_CONFIG; | ||
} | ||
} | ||
exports.findConfiguration = findConfiguration; | ||
function getHomeDir() { | ||
var environment = global.process.env; | ||
var paths = [environment.USERPROFILE, environment.HOME, environment.HOMEPATH, environment.HOMEDRIVE + environment.HOMEPATH]; | ||
for (var homeIndex in paths) { | ||
if (paths.hasOwnProperty(homeIndex)) { | ||
var homePath = paths[homeIndex]; | ||
if (homePath && fs.existsSync(homePath)) { | ||
return homePath; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as Lint from "./lint"; | ||
import * as ts from "typescript"; | ||
export declare class EnableDisableRulesWalker extends Lint.SkippableTokenAwareRuleWalker { | ||
enableDisableRuleMap: { | ||
[rulename: string]: Lint.IEnableDisablePosition[]; | ||
}; | ||
visitSourceFile(node: ts.SourceFile): void; | ||
private handlePossibleTslintSwitch(commentText, startingPosition); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
/* | ||
* Copyright 2014 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var Lint = require("./lint"); | ||
var ts = require("typescript"); | ||
var EnableDisableRulesWalker = (function (_super) { | ||
__extends(EnableDisableRulesWalker, _super); | ||
function EnableDisableRulesWalker() { | ||
_super.apply(this, arguments); | ||
this.enableDisableRuleMap = {}; | ||
} | ||
EnableDisableRulesWalker.prototype.visitSourceFile = function (node) { | ||
var _this = this; | ||
_super.prototype.visitSourceFile.call(this, node); | ||
var scan = ts.createScanner(1 /* ES5 */, false, 0 /* Standard */, node.text); | ||
Lint.scanAllTokens(scan, function (scanner) { | ||
var startPos = scanner.getStartPos(); | ||
if (_this.tokensToSkipStartEndMap[startPos] != null) { | ||
// tokens to skip are places where the scanner gets confused about what the token is, without the proper context | ||
// (specifically, regex, identifiers, and templates). So skip those tokens. | ||
scanner.setTextPos(_this.tokensToSkipStartEndMap[startPos]); | ||
return; | ||
} | ||
if (scanner.getToken() === 3 /* MultiLineCommentTrivia */) { | ||
var commentText = scanner.getTokenText(); | ||
var startPosition = scanner.getTokenPos(); | ||
_this.handlePossibleTslintSwitch(commentText, startPosition); | ||
} | ||
}); | ||
}; | ||
EnableDisableRulesWalker.prototype.handlePossibleTslintSwitch = function (commentText, startingPosition) { | ||
var _this = this; | ||
var currentPosition = startingPosition; | ||
// regex is: start of string followed by "/*" followed by any amount of whitespace followed by "tslint:" | ||
if (commentText.match(/^\/\*\s*tslint:/)) { | ||
var commentTextParts = commentText.split(":"); | ||
// regex is: start of string followed by either "enable" or "disable" | ||
// followed by either whitespace or end of string | ||
var enableOrDisableMatch = commentTextParts[1].match(/^(enable|disable)(\s|$)/); | ||
if (enableOrDisableMatch != null) { | ||
var isEnabled = enableOrDisableMatch[1] === "enable"; | ||
var position = currentPosition; | ||
var rulesList = ["all"]; | ||
if (commentTextParts.length > 2) { | ||
rulesList = commentTextParts[2].split(/\s+/); | ||
} | ||
rulesList.forEach(function (ruleToAdd) { | ||
if (!(ruleToAdd in _this.enableDisableRuleMap)) { | ||
_this.enableDisableRuleMap[ruleToAdd] = []; | ||
} | ||
_this.enableDisableRuleMap[ruleToAdd].push({ | ||
isEnabled: isEnabled, | ||
position: position | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
return EnableDisableRulesWalker; | ||
})(Lint.SkippableTokenAwareRuleWalker); | ||
exports.EnableDisableRulesWalker = EnableDisableRulesWalker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function findFormatter(name: string, formattersDirectory?: string): any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2013 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var underscore_string_1 = require("underscore.string"); | ||
var moduleDirectory = path.dirname(module.filename); | ||
var CORE_FORMATTERS_DIRECTORY = path.resolve(moduleDirectory, "..", "build", "formatters"); | ||
function findFormatter(name, formattersDirectory) { | ||
if (typeof (name) === "function") { | ||
return name; | ||
} | ||
var camelizedName = underscore_string_1.camelize(name + "Formatter"); | ||
// first check for core formatters | ||
var Formatter = loadFormatter(CORE_FORMATTERS_DIRECTORY, camelizedName); | ||
if (Formatter) { | ||
return Formatter; | ||
} | ||
// then check for rules within the first level of rulesDirectory | ||
if (formattersDirectory) { | ||
Formatter = loadFormatter(formattersDirectory, camelizedName); | ||
if (Formatter) { | ||
return Formatter; | ||
} | ||
} | ||
// else try to resolve as module | ||
return loadFormatterModule(name); | ||
} | ||
exports.findFormatter = findFormatter; | ||
function loadFormatter() { | ||
var paths = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
paths[_i - 0] = arguments[_i]; | ||
} | ||
var formatterPath = paths.reduce(function (p, c) { return path.join(p, c); }, ""); | ||
var fullPath = path.resolve(moduleDirectory, formatterPath); | ||
if (fs.existsSync(fullPath + ".js")) { | ||
var formatterModule = require(fullPath); | ||
return formatterModule.Formatter; | ||
} | ||
return undefined; | ||
} | ||
function loadFormatterModule(name) { | ||
var src; | ||
try { | ||
src = require.resolve(name); | ||
} | ||
catch (e) { | ||
return undefined; | ||
} | ||
return require(src).Formatter; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./language/formatter/abstractFormatter"; | ||
export * from "./formatters/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
__export(require("./language/formatter/abstractFormatter")); | ||
__export(require("./formatters/index")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./jsonFormatter"; | ||
export * from "./pmdFormatter"; | ||
export * from "./proseFormatter"; | ||
export * from "./verboseFormatter"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
__export(require("./jsonFormatter")); | ||
__export(require("./pmdFormatter")); | ||
__export(require("./proseFormatter")); | ||
__export(require("./verboseFormatter")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as Lint from "../lint"; | ||
export declare class Formatter extends Lint.Formatters.AbstractFormatter { | ||
format(failures: Lint.RuleFailure[]): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
/* | ||
* Copyright 2013 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var Lint = require("../lint"); | ||
var Formatter = (function (_super) { | ||
__extends(Formatter, _super); | ||
function Formatter() { | ||
_super.apply(this, arguments); | ||
} | ||
Formatter.prototype.format = function (failures) { | ||
var failuresJSON = failures.map(function (failure) { return failure.toJson(); }); | ||
return JSON.stringify(failuresJSON); | ||
}; | ||
return Formatter; | ||
})(Lint.Formatters.AbstractFormatter); | ||
exports.Formatter = Formatter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as Lint from "../lint"; | ||
export declare class Formatter extends Lint.Formatters.AbstractFormatter { | ||
format(failures: Lint.RuleFailure[]): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
/* | ||
* Copyright 2013 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var Lint = require("../lint"); | ||
var Formatter = (function (_super) { | ||
__extends(Formatter, _super); | ||
function Formatter() { | ||
_super.apply(this, arguments); | ||
} | ||
Formatter.prototype.format = function (failures) { | ||
var output = "<pmd version=\"tslint\">"; | ||
for (var _i = 0; _i < failures.length; _i++) { | ||
var failure = failures[_i]; | ||
var failureString = failure.getFailure() | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/\'/g, "'") | ||
.replace(/\"/g, """); | ||
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter(); | ||
output += "<file name=\"" + failure.getFileName(); | ||
output += "\"><violation begincolumn=\"" + (lineAndCharacter.character + 1); | ||
output += "\" beginline=\"" + (lineAndCharacter.line + 1); | ||
output += "\" priority=\"1\""; | ||
output += " rule=\"" + failureString + "\"> </violation></file>"; | ||
} | ||
output += "</pmd>"; | ||
return output; | ||
}; | ||
return Formatter; | ||
})(Lint.Formatters.AbstractFormatter); | ||
exports.Formatter = Formatter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as Lint from "../lint"; | ||
export declare class Formatter extends Lint.Formatters.AbstractFormatter { | ||
format(failures: Lint.RuleFailure[]): string; | ||
} |
Oops, something went wrong.