How to use the tslint.Utils function in tslint

To help you get started, we’ve selected a few tslint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buzinas / tslint-eslint-rules / src / rules / terNoMixedSpacesAndTabsRule.ts View on Github external
import { getLineRanges, getTokenAtPosition, isPositionInComment } from 'tsutils';

const RULE_NAME = 'ter-no-mixed-spaces-and-tabs';
interface ITerNoMixedSpacesAndTabsRuleOptions {
  readonly tabs?: boolean;
  readonly smartTabs: boolean;
}

const OPTION_USE_TABS = 'tabs';
const OPTION_USE_SPACES = 'spaces';

export class Rule extends Lint.Rules.AbstractRule {
  public static metadata: Lint.IRuleMetadata = {
    ruleName: RULE_NAME,
    description: 'Enforces indentation with unmixed tabs or spaces.',
    rationale: Lint.Utils.dedent`
      Using only one of tabs or spaces for indentation leads to more consistent editor behavior,
      cleaner diffs in version control, and easier programmatic manipulation.`,
    optionsDescription: Lint.Utils.dedent`
      This rule takes an object argument with an optional \`type\` property which can be set to:

      * \`${OPTION_USE_SPACES}\` enforces consistent spaces for indentation.
      * \`${OPTION_USE_TABS}\` enforces consistent tabs for indentation.

      If the above is not provided, the rule will enforce either all tabs or all spaces on each
      line, although different lines may differ between tabs and spaces.

      Optionally, a \`smartTabs\` boolean property can be specified.  If set to true, smart tabs
      allow mixing tabs and spaces if tabs are used for indentation and spaces for alignment, eg.

          function main() {
          // --->const a = 1,
github palantir / tslint-react / src / rules / jsxBanPropsRule.ts View on Github external
import * as Lint from "tslint";
import { isIdentifier, isJsxAttribute } from "tsutils/typeguard/3.0";
import * as ts from "typescript";

interface IRuleOptions {
    /** Map from banned prop name -> its explanatory message */
    bannedProps: Map;
}

export class Rule extends Lint.Rules.AbstractRule {
    /* tslint:disable:object-literal-sort-keys */
    public static metadata: Lint.IRuleMetadata = {
        ruleName: "jsx-ban-props",
        description: "Bans the use of specific props.",
        optionsDescription: Lint.Utils.dedent`
            A list of \`['propName', 'optional explanation here']\` which bans the prop called 'propName'.`,
        options: {
            type: "list",
            listType: {
                type: "string",
                items: {type: "string"},
                minLength: 1,
                maxLength: 2,
            },
        },
        optionExamples: [`[true, ["someProp], ["anotherProp", "Optional explanation"]]`],
        type: "functionality",
        typescriptOnly: false,
    };
    /* tslint:enable:object-literal-sort-keys */
github palantir / tslint-react / src / rules / jsxNoLambdaRule.ts View on Github external
* 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.
 */

import * as Lint from "tslint";
import { isJsxAttribute, isJsxExpression } from "tsutils/typeguard/3.0";
import * as ts from "typescript";

export class Rule extends Lint.Rules.AbstractRule {
    /* tslint:disable:object-literal-sort-keys */
    public static metadata: Lint.IRuleMetadata = {
        ruleName: "jsx-no-lambda",
        description: "Checks for fresh lambda literals used in JSX attributes",
        descriptionDetails: Lint.Utils.dedent
            `Creating new anonymous functions (with either the function syntax or \
            ES2015 arrow syntax) inside the render call stack works against pure component \
            rendering. When doing an equality check between two lambdas, React will always \
            consider them unequal values and force the component to re-render more often than necessary.`,
        options: null,
        optionsDescription: "",
        optionExamples: ["true"],
        type: "functionality",
        typescriptOnly: false,
    };
    /* tslint:enable:object-literal-sort-keys */

    public static FAILURE_STRING = "Lambdas are forbidden in JSX attributes due to their rendering performance impact";

    public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
        return this.applyWithFunction(sourceFile, walk);
github buzinas / tslint-eslint-rules / src / rules / terNoMixedSpacesAndTabsRule.ts View on Github external
}
          },
          additionalProperties: false
        }
      ],
      minLength: 0,
      maxLength: 1
    },
    optionExamples: [
      Lint.Utils.dedent`
      "${RULE_NAME}": { "type": "${OPTION_USE_TABS}" } ]
      `,
      Lint.Utils.dedent`
      "${RULE_NAME}": { "type": "${OPTION_USE_SPACES}" } ]
      `,
      Lint.Utils.dedent`
      "${RULE_NAME}": { "smartTabs": true } ]
      `,
      Lint.Utils.dedent`
      "${RULE_NAME}": { "type": "${OPTION_USE_TABS}", "smartTabs": true } ]
      `
    ],
    type: 'maintainability',
    typescriptOnly: false
  };

  public static FAILURE_STRING(expected: string, mixed?: boolean): string {
    if (!mixed) {
      return `${expected} indentation expected`;
    }

    return `indentation has mixed tabs and spaces`;
github bfwg / angular-spring-starter / frontend / node_modules / codelyzer / directiveSelectorRule.js View on Github external
if (prefixes.length === 1) {
            return 'The selector of the directive "%s" should have prefix "%s" (https://goo.gl/uacjKR)';
        }
        else {
            return 'The selector of the directive "%s" should have one of the prefixes "%s" (https://goo.gl/uacjKR)';
        }
    };
    return Rule;
}(selectorNameBase_1.SelectorRule));
Rule.metadata = {
    ruleName: 'directive-selector',
    type: 'style',
    description: "Directive selectors should follow given naming rules.",
    descriptionDetails: "See more at https://angular.io/styleguide#!#02-07, https://angular.io/styleguide#!#05-02, " +
        "and https://angular.io/styleguide#!#05-03.",
    rationale: (_a = ["\n    * Consistent conventions make it easy to quickly identify and reference assets of different types.\n    * Makes it easier to promote and share the directive in other apps.\n    * Directives are easy to identify in the DOM.\n    * It is easier to recognize that a symbol is a directive by looking at the template's HTML.\n    "], _a.raw = ["\n    * Consistent conventions make it easy to quickly identify and reference assets of different types.\n    * Makes it easier to promote and share the directive in other apps.\n    * Directives are easy to identify in the DOM.\n    * It is easier to recognize that a symbol is a directive by looking at the template's HTML.\n    "], Lint.Utils.dedent(_a)),
    options: {
        'type': 'array',
        'items': [
            {
                'enum': ['element', 'attribute']
            },
            {
                'oneOf': [
                    {
                        'type': 'array',
                        'items': {
                            'type': 'string'
                        }
                    },
                    {
                        'type': 'string'
github buzinas / tslint-eslint-rules / src / rules / terFuncCallSpacingRule.ts View on Github external
properties: {
            allowNewlines: {
              type: 'boolean'
            }
          },
          additionalProperties: false
        }
      ],
      minItems: 0,
      maxItems: 2
    },
    optionExamples: [
      Lint.Utils.dedent`
        "${RULE_NAME}": [true]
        `,
      Lint.Utils.dedent`
        "${RULE_NAME}": [true, "always"]
        `,
      Lint.Utils.dedent`
        "${RULE_NAME}": [true, "always", { allowNewlines: true }]
        `
    ],
    typescriptOnly: false,
    type: 'style'
  };

  public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
    const options = {
      expectSpace: false,
      spacePattern: /\s/
    };
github buzinas / tslint-eslint-rules / dist / rules / terArrowSpacingRule.js View on Github external
items: [{
                type: 'object',
                properties: {
                    before: {
                        type: 'boolean'
                    },
                    after: {
                        type: 'boolean'
                    }
                },
                additionalProperties: false
            }],
        maxLength: 1
    },
    optionExamples: [
        (_c = ["\n        \"", "\": [true]\n        "], _c.raw = ["\n        \"", "\": [true]\n        "], Lint.Utils.dedent(_c, RULE_NAME)),
        (_d = ["\n        \"", "\": [true, {\n          \"before\": false,\n          \"after\": false\n        }]\n        "], _d.raw = ["\n        \"", "\": [true, {\n          \"before\": false,\n          \"after\": false\n        }]\n        "], Lint.Utils.dedent(_d, RULE_NAME))
    ],
    typescriptOnly: false,
    type: 'style'
};
exports.Rule = Rule;
var RuleWalker = (function (_super) {
    __extends(RuleWalker, _super);
    function RuleWalker(sourceFile, options) {
        var _this = _super.call(this, sourceFile, options) || this;
        _this.before = true;
        _this.after = true;
        var opt = _this.getOptions();
        if (opt[0]) {
            _this.before = opt[0].before !== false;
            _this.after = opt[0].after !== false;
github buzinas / tslint-eslint-rules / src / rules / terArrowBodyStyleRule.ts View on Github external
/**
 * Eslint port: https://github.com/eslint/eslint/blob/master/lib/rules/arrow-body-style.js
 * Github Commit Hash: 2bd1dd71c32d286cde10c52140a1d26f2a512a30
 */
import * as ts from 'typescript';
import * as Lint from 'tslint';

const RULE_NAME = 'ter-arrow-body-style';

export class Rule extends Lint.Rules.AbstractRule {
  public static metadata: Lint.IRuleMetadata = {
    ruleName: RULE_NAME,
    description: 'require braces in arrow function body',
    rationale: Lint.Utils.dedent`
      Arrow functions have two syntactic forms for their function bodies. They may be defined with
      a block body (denoted by curly braces) \`() => { ... }\` or with a single expression
      \`() => ...\`, whose value is implicitly returned.
      `,
    optionsDescription: Lint.Utils.dedent`
      The rule takes one or two options. The first is a string, which can be:

      - \`"always"\` enforces braces around the function body
      - \`"as-needed"\` enforces no braces where they can be omitted (default)
      - \`"never"\` enforces no braces around the function body (constrains arrow functions to the
                    role of returning an expression)

      The second one is an object for more fine-grained configuration when the first option is
      \`"as-needed"\`. Currently, the only available option is \`requireReturnForObjectLiteral\`, a
      boolean property. It’s false by default. If set to true, it requires braces and an explicit
      return for object literals.
github buzinas / tslint-eslint-rules / src / rules / arrayBracketSpacingRule.ts View on Github external
type: 'boolean'
            },
            objectsInArrays: {
              type: 'boolean'
            },
            arraysInArrays: {
              type: 'boolean'
            }
          },
          additionalProperties: false
        }

      ]
    },
    optionExamples: [
      Lint.Utils.dedent`
        "${RULE_NAME}": [true, "always"]
        `,
      Lint.Utils.dedent`
        "${RULE_NAME}": [true, "never"]
        `,
      Lint.Utils.dedent`
        "${RULE_NAME}": [true, "never", {
          "arraysInArrays": true
        }]
        `
    ],
    typescriptOnly: false,
    type: 'style'
  };

  public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
github mgechev / codelyzer / docs / dist / src / useInputPropertyDecoratorRule.js View on Github external
__extends(Rule, _super);
    function Rule(options) {
        return _super.call(this, {
            decoratorName: 'Input',
            propertyName: 'inputs',
            errorMessage: 'Use the @Input property decorator instead of the inputs property ($$05-12$$)'
        }, options) || this;
    }
    return Rule;
}(propertyDecoratorBase_1.UsePropertyDecorator));
Rule.metadata = {
    ruleName: 'use-input-property-decorator',
    type: 'style',
    description: "Use `@Input` decorator rather than the `inputs` property of `@Component` and `@Directive` metadata.",
    descriptionDetails: "See more at https://angular.io/styleguide#!#05-12.",
    rationale: (_a = ["\n    * It is easier and more readable to identify which properties in a class are inputs.\n    * If you ever need to rename the property name associated with `@Input`, you can modify it in a single place.\n    * The metadata declaration attached to the directive is shorter and thus more readable.\n    * Placing the decorator on the same line usually makes for shorter code and still easily identifies the property as an input."], _a.raw = ["\n    * It is easier and more readable to identify which properties in a class are inputs.\n    * If you ever need to rename the property name associated with \\`@Input\\`, you can modify it in a single place.\n    * The metadata declaration attached to the directive is shorter and thus more readable.\n    * Placing the decorator on the same line usually makes for shorter code and still easily identifies the property as an input."], Lint.Utils.dedent(_a)),
    options: null,
    optionsDescription: "Not configurable.",
    typescriptOnly: true,
};
exports.Rule = Rule;
var _a;