Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Incorrectly receive statements are not aligned error with align rule #2640

Closed
unicron opened this issue Apr 26, 2017 · 2 comments · Fixed by #2642 or singapore/lint-condo#282
Closed

Comments

@unicron
Copy link

unicron commented Apr 26, 2017

Bug Report

  • TSLint version: 5.1.0
  • TypeScript version: 2.2.2
  • Running TSLint via: (pick one) Node.js

TypeScript code being linted

import Backbone = require('backbone');
import Marionette = require('backbone.marionette');
import { LoggingService, LogLevel } from '../util/logging/LoggingService';

export class AitrItemView<T extends Backbone.Model> extends Marionette.ItemView<T> {
    public handleError(error: any, command: string) {
        error = error || 'Error processing command';
        let message = error.message || error.Message || error;
        if (command) {
            message = command + ' failed.\n    ' + message;
        }

        LoggingService.log(message, LogLevel.error, error);
    }
}

with tslint.json configuration:

{
    "defaultSeverity": "error",
    "extends": [
        "tslint:latest"
    ],
    "jsRules": {},
    "rules": {
        "quotemark": [true, "single", "avoid-escape"],
        "max-line-length": [false],
        "prefer-const": false,
        "max-classes-per-file": [false],
        "ordered-imports": false,
        "object-literal-sort-keys": false,
        "comment-format": false,
        "only-arrow-functions": false,
        "member-ordering": false,
        "member-access": false,
        "no-bitwise": false,
        "trailing-comma": false,
        "object-literal-shorthand": false,
        "variable-name": [true, "ban-keywords", "check-format"],
        "no-var-requires": false,
        "no-consecutive-blank-lines": [true, 2],
        "one-line": [true, "check-catch", "check-finally", "check-else", "check-open-brace"],
        "interface-name": false,
        "object-literal-key-quotes": [true, "consistent"],
        "ban-types": false,
        "space-before-function-paren": false,
        "typedef": [true, "parameter", "arrow-parameter", "property-declaration", "member-variable-declaration", "object-destructuring", "array-destructuring"],
        "no-namespace": false,
        "prefer-for-of": false
    },
    "rulesDirectory": []
}

Actual behavior

running npm run tslint runs tslint --project ./tslint.json which produces the following errors:
ERROR: app/aitr/Aitr.ItemView.ts[2, 1]: statements are not aligned
ERROR: app/aitr/Aitr.ItemView.ts[3, 1]: statements are not aligned
ERROR: app/aitr/Aitr.ItemView.ts[5, 1]: statements are not aligned

If run with --fix option, the code is modified to insert a single space as the first character in front of all three lines, as below. This is incorrect, as the statements are already aligned.

import Backbone = require('backbone');
 import Marionette = require('backbone.marionette');
 import { LoggingService, LogLevel } from '../util/logging/LoggingService';

 export class AitrItemView<T extends Backbone.Model> extends Marionette.ItemView<T> {
    public handleError(error: any, command: string) {
        error = error || 'Error processing command';
        let message = error.message || error.Message || error;
        if (command) {
            message = command + ' failed.\n    ' + message;
        }

        LoggingService.log(message, LogLevel.error, error);
    }
}

This error is repeated for MANY other files, but not for all files in my project.

Expected behavior

No errors generated from above code.

@ajafff
Copy link
Contributor

ajafff commented Apr 26, 2017

This happens for files encoded in UTF8 with BOM, when the first statement is on the first line.
I recently fixed the same problem for jsdoc-format. I'm already working on a fix.

nchen63 pushed a commit that referenced this issue Apr 29, 2017
[bugfix] `align`: fix false positive for files with BOM
Fixes: #2640
@unicron
Copy link
Author

unicron commented May 1, 2017

Thanks for getting this done quickly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants