diff --git a/build/lib/tslint/noNewBufferRule.js b/build/lib/tslint/noNewBufferRule.js new file mode 100644 index 00000000000..ae9b02d457e --- /dev/null +++ b/build/lib/tslint/noNewBufferRule.js @@ -0,0 +1,22 @@ +"use strict"; +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +Object.defineProperty(exports, "__esModule", { value: true }); +const ts = require("typescript"); +const Lint = require("tslint"); +class Rule extends Lint.Rules.AbstractRule { + apply(sourceFile) { + return this.applyWithWalker(new NewBufferRuleWalker(sourceFile, this.getOptions())); + } +} +exports.Rule = Rule; +class NewBufferRuleWalker extends Lint.RuleWalker { + visitNewExpression(node) { + if (node.expression.kind === ts.SyntaxKind.Identifier && node.expression && node.expression.text === 'Buffer') { + this.addFailureAtNode(node, '`new Buffer` is deprecated. Consider Buffer.From or Buffer.alloc instead.'); + } + super.visitNewExpression(node); + } +} diff --git a/build/lib/tslint/noNewBufferRule.ts b/build/lib/tslint/noNewBufferRule.ts new file mode 100644 index 00000000000..7b0dd43e538 --- /dev/null +++ b/build/lib/tslint/noNewBufferRule.ts @@ -0,0 +1,23 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as ts from 'typescript'; +import * as Lint from 'tslint'; + +export class Rule extends Lint.Rules.AbstractRule { + apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithWalker(new NewBufferRuleWalker(sourceFile, this.getOptions())); + } +} + +class NewBufferRuleWalker extends Lint.RuleWalker { + visitNewExpression(node: ts.NewExpression) { + if (node.expression.kind === ts.SyntaxKind.Identifier && node.expression && (node.expression as ts.Identifier).text === 'Buffer') { + this.addFailureAtNode(node, '`new Buffer` is deprecated. Consider Buffer.From or Buffer.alloc instead.'); + } + + super.visitNewExpression(node); + } +} \ No newline at end of file diff --git a/tslint.json b/tslint.json index 7f1388dfa76..476f99d2237 100644 --- a/tslint.json +++ b/tslint.json @@ -523,6 +523,7 @@ } ], "duplicate-imports": true, + "no-new-buffer": true, "translation-remind": true, "no-standalone-editor": true },