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

New Rule: max-file-line-count #1360

Merged
merged 20 commits into from
Jul 26, 2016
Merged

New Rule: max-file-line-count #1360

merged 20 commits into from
Jul 26, 2016

Conversation

ChrisMBarr
Copy link
Contributor

Adding a new rule that limits the number of lines that a file can contain. When files go over this limit it's usually a sign that the code is too complex, or it has too many responsibilities and it needs to be broken up into smaller pieces.

The goal here is to count the number of lines, and it should match the line number display in your IDE (meaning things like blank lines, comments, etc. are included in this count)

If the rule disabling comment /* tslint:disable:max-file-line-count */ is added anywhere in the file, this rule is ignored for the file.

@jkillian
Copy link
Contributor

jkillian commented Jul 20, 2016

I think file-max-line-count would fall more in line with how other rules are named.

Although that would technically mean our other rule should be named line-max-length... We really need to specify rule naming conventions haha (#1371 )


if (lineCount > lineLimit && disabledIntervals.length === 0) {
const errorString = Rule.FAILURE_STRING_FACTORY(lineCount, lineLimit);
ruleFailures.push(new Lint.RuleFailure(sourceFile, 0, 0, errorString, this.getOptions().ruleName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making this a zero-length error, can we make it either one character long or the length of the first line?

@jkillian
Copy link
Contributor

Looking good, thanks @ChrisMBarr! Can you make the small changes noted above and merge master into this?

@jkillian
Copy link
Contributor

Let's just stay with max-file-line-count as the name, no need to change it

corydeppen and others added 16 commits July 25, 2016 14:31
Now when something is unused it fails with a specific message about what it is, instead of just calling everything a "variable".

The types that can be reported are:
* function 🆕
* import 🆕
* parameter 🆕
* property 🆕
* variable
Addresses #1323.

* Changed `Linter` to accept an optional program object in the constructor
  * Added helper functions for creating a program using a tsconfig and getting relevant files
* Created `TypedRule` class which receives the program object
  * Rules extending this class must implement `applyWithProgram`
  * `Linter` passes program to `TypedRule`s if available
  * Calling `apply` on a `TypedRule` throws an error
* Added `requiresTypeInfo` boolean to metadata
* Created `ProgramAwareRuleWalker` which walks with the program / typechecker
* Added cli options `--project` and `--type-check`
  * `--project` takes a `tsconfig.json` file
  * `--type-check` enables type checking and `TypedRule`s, requires `--project`
* Added an example `restrictPlusOperands` rule and tests that uses types
* Add linterOptions to tslint.json

- only enable type checking during tests when typeCheck: true is configured
- fixes #1402

* Code style
* Add new Rule: arrow-parens

* Add test

* modify some documentations
* Core quote-props rule

* Tweaks for code review

* rename
…1349)

* Implement rule to forbid return statements in finally blocks #1097

* explore the try statement fully to pick up violations in nested scopes

* switch to a scope aware rule walker to reduce number of passes over the AST

* Add support for other control flow statements in finally blocks (break, continue, throws)

* improve the rationale description for the no unsafe finally rule

* rename rule to no-unsafe-finally to be inline with eslint

* add new rule to latest config

* pull out helper functions from the walker class.

* fix tslint violations (which didn't occur locally)
* task(formatter): added stylish formatter

* Support non-colors terminal in tests

* fix(stylish): lint quotes

* fix(stylish) 4 spaces indentation

* fix(stylish): correct strpad amount

* fix(stylish): test tuple position
@jkillian jkillian merged commit 6202637 into palantir:master Jul 26, 2016
@jkillian
Copy link
Contributor

Thanks @ChrisMBarr, merged!

@ChrisMBarr ChrisMBarr deleted the max-file-line-count-rule branch July 26, 2016 12:45
soniro pushed a commit to soniro/tslint that referenced this pull request Aug 31, 2016
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 this pull request may close these issues.