Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ts = require("typescript");
var Lint = require("tslint/lib/lint");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new NoPublicMemberWithoutCommentWalker(sourceFile, this.getOptions()));
};
Rule.FAILURE_STRING = "public or protected method must have doc comment";
return Rule;
})(Lint.Rules.AbstractRule);
exports.Rule = Rule;
// The walker takes care of all the work.
var NoPublicMemberWithoutCommentWalker = (function (_super) {
__extends(NoPublicMemberWithoutCommentWalker, _super);
function NoPublicMemberWithoutCommentWalker() {
_super.apply(this, arguments);
}
NoPublicMemberWithoutCommentWalker.prototype.visitMethodDeclaration = function (node) {
if (this._isPublic(node) || this._isProtected(node)) {
var modifiers = this.sourceFile.text.substring(node.pos, node.modifiers.end);
if (!/\/\*\*/m.test(modifiers)) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + " at: " + node.name.text));
}
}
// call the base version of this visitor to actually parse this node
_super.prototype.visitMethodDeclaration.call(this, node);
if (sourceFile === undefined) {
throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts or .tsx extension.`);
}
// walk the code first to find all the intervals where rules are disabled
const rulesWalker = new EnableDisableRulesWalker(sourceFile, {
disabledIntervals: [],
ruleName: '',
});
rulesWalker.walk(sourceFile);
const enableDisableRuleMap = rulesWalker.enableDisableRuleMap;
for (let rule of enabledRules) {
let ruleFailures: Linter.RuleFailure[] = [];
if (rule instanceof Linter.Rules.TypedRule) {
console.error('Does not support TypedRules');
} else {
ruleFailures = rule.apply(sourceFile);
}
for (let ruleFailure of ruleFailures) {
if (!this.containsRule(this.failures, ruleFailure)) {
this.failures.push(ruleFailure);
}
}
}
}
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 __());
};
var Lint = require("tslint/lib/lint");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new NoImplicitReturnTypeWalker(sourceFile, this.getOptions()));
};
Rule.FAILURE_STRING = "No implicit return value type is forbidden";
return Rule;
})(Lint.Rules.AbstractRule);
exports.Rule = Rule;
// The walker takes care of all the work.
var NoImplicitReturnTypeWalker = (function (_super) {
__extends(NoImplicitReturnTypeWalker, _super);
function NoImplicitReturnTypeWalker() {
_super.apply(this, arguments);
}
NoImplicitReturnTypeWalker.prototype.visitMethodDeclaration = function (node) {
if (!node.type) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + " at: " + node.name.text));
}
//if(node.type)console.log(this.sourceFile.text.substring(node.type.pos,node.type.end));
// call the base version of this visitor to actually parse this node
_super.prototype.visitMethodDeclaration.call(this, node);
};
NoImplicitReturnTypeWalker.prototype.visitPropertyDeclaration = function (node) {
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ts = require('typescript');
var Lint = require('tslint/lib/lint');
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new ImportDestructuringSpacingWalker(sourceFile, this.getOptions()));
};
Rule.FAILURE_STRING = "Style 03-05 Import Destructuring Spacing";
return Rule;
})(Lint.Rules.AbstractRule);
exports.Rule = Rule;
// The walker takes care of all the work.
var ImportDestructuringSpacingWalker = (function (_super) {
__extends(ImportDestructuringSpacingWalker, _super);
function ImportDestructuringSpacingWalker(sourceFile, options) {
_super.call(this, sourceFile, options);
this.scanner = ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, sourceFile.text);
}
ImportDestructuringSpacingWalker.prototype.visitImportDeclaration = function (node) {
var importClause = node.importClause;
if (importClause != null && importClause.namedBindings != null) {
var text = importClause.namedBindings.getText();
if (!this.checkForWhiteSpace(text)) {
this.addFailure(this.createFailure(importClause.namedBindings.getStart(), importClause.namedBindings.getWidth(), Rule.FAILURE_STRING));
}
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ts = require("typescript");
var Lint = require("tslint/lib/lint");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
var noMutationWalker = new NoMutationWalker(sourceFile, this.getOptions());
return this.applyWithWalker(noMutationWalker);
};
Rule.FAILURE_STRING = "No object mutation allowed.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var NoMutationWalker = (function (_super) {
__extends(NoMutationWalker, _super);
function NoMutationWalker() {
_super.apply(this, arguments);
}
NoMutationWalker.prototype.visitNode = function (node) {
if (node && node.kind === ts.SyntaxKind.BinaryExpression
&& node.getChildCount() >= 3
&& node.getChildAt(0).kind === ts.SyntaxKind.PropertyAccessExpression
&& node.getChildAt(1).kind === ts.SyntaxKind.FirstAssignment) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
}
_super.prototype.visitNode.call(this, node);
};
return NoMutationWalker;
import * as ts from 'typescript';
import * as Lint from 'tslint/lib/lint';
import {ErrorTolerantWalker} from './utils/ErrorTolerantWalker';
import {ExtendedMetadata} from './utils/ExtendedMetadata';
const FAILURE_STRING: string = 'Title elements must not be empty';
/**
* Implementation of the react-a11y-titles rule.
*/
export class Rule extends Lint.Rules.AbstractRule {
public static metadata: ExtendedMetadata = {
ruleName: 'react-a11y-titles',
type: 'functionality',
description: 'For accessibility of your website, HTML title elements must not be empty.',
options: null,
issueClass: 'Ignored',
issueType: 'Warning',
severity: 'Moderate',
level: 'Opportunity for Excellence',
group: 'Accessibility'
};
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
if (sourceFile.languageVariant === ts.LanguageVariant.JSX) {
return this.applyWithWalker(new ReactA11yTitlesRuleWalker(sourceFile, this.getOptions()));
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 __());
};
var Lint = require("tslint/lib/lint");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new NoDuplicateImportsFromSameFileWalker(sourceFile, this.getOptions()));
};
return Rule;
}(Lint.Rules.AbstractRule));
Rule.FAILURE_STRING = "duplicate imports from same file forbidden";
exports.Rule = Rule;
var NoDuplicateImportsFromSameFileWalker = (function (_super) {
__extends(NoDuplicateImportsFromSameFileWalker, _super);
function NoDuplicateImportsFromSameFileWalker() {
var _this = _super.apply(this, arguments) || this;
_this.fileImportsByFileName = {};
return _this;
}
NoDuplicateImportsFromSameFileWalker.prototype.visitImportDeclaration = function (node) {
var sourceFile = node.parent;
var fileImports = this.getFileImports(sourceFile.fileName);
var importPath = node.moduleSpecifier.text;
if (fileImports[importPath] != null) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
}
import * as Lint from 'tslint/lib/lint';
import * as ts from 'typescript';
import {sprintf} from 'sprintf-js';
interface IWalker{
new (sourceFile:ts.SourceFile, languageService:ts.LanguageService, rule):Lint.RuleWalker;
}
export class RuleBase extends Lint.Rules.AbstractRule {
constructor(ruleName:string, value:any, disabledIntervals:Lint.IDisabledInterval[], private validator:Function,
private errorMessage:string, private Walker:IWalker) {
super(ruleName, value, disabledIntervals);
}
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
let documentRegistry = ts.createDocumentRegistry();
let languageServiceHost = Lint.createLanguageServiceHost('file.ts', sourceFile.getFullText());
let languageService:ts.LanguageService = ts.createLanguageService(languageServiceHost, documentRegistry);
let walker = new this.Walker(sourceFile, languageService, this);
return this.applyWithWalker(walker);
}
public validate(parameter:ts.ParameterDeclaration):boolean {
return this.validator(parameter);
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 __());
};
var Lint = require("tslint/lib/lint");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new NoDuplicateImportsFromSameFileWalker(sourceFile, this.getOptions()));
};
Rule.FAILURE_STRING = "duplicate imports from same file forbidden";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var NoDuplicateImportsFromSameFileWalker = (function (_super) {
__extends(NoDuplicateImportsFromSameFileWalker, _super);
function NoDuplicateImportsFromSameFileWalker() {
_super.apply(this, arguments);
this.fileImportsByFileName = {};
}
NoDuplicateImportsFromSameFileWalker.prototype.visitImportDeclaration = function (node) {
var sourceFile = node.parent;
var fileImports = this.getFileImports(sourceFile.fileName);
var importPath = node.moduleSpecifier.text;
if (fileImports[importPath] != null) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
}
else {
fileImports[importPath] = true;
import * as ts from 'typescript';
import * as Lint from 'tslint/lib/lint';
import {ErrorTolerantWalker} from './utils/ErrorTolerantWalker';
import {SyntaxKind} from './utils/SyntaxKind';
import {AstUtils} from './utils/AstUtils';
import {Utils} from './utils/Utils';
import {ExtendedMetadata} from './utils/ExtendedMetadata';
const FAILURE_STRING: string = 'A stateless class was found. This indicates a failure in the object model: ';
/**
* Implementation of the no-stateless-classes rule.
*/
export class Rule extends Lint.Rules.AbstractRule {
public static metadata: ExtendedMetadata = {
ruleName: 'no-stateless-class',
type: 'maintainability',
description: 'A stateless class represents a failure in the object oriented design of the system.',
options: null,
issueClass: 'Non-SDL',
issueType: 'Warning',
severity: 'Important',
level: 'Opportunity for Excellence',
group: 'Correctness',
commonWeaknessEnumeration: '398, 710'
};
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoStatelessClassRuleWalker(sourceFile, this.getOptions()));