max line length exceeded

Requires lines to be under a certain max length.

Rationale

Limiting the length of a line of code improves code readability. It also makes comparing code side-by-side easier and improves compatibility with various editors, IDEs, and diff viewers.

Config

It can take one argument, which can be any of the following:

  • integer indicating maximum length of lines.
  • object with keys:
    • limit — number greater than 0 defining the max line length
    • ignore-pattern — string defining ignore pattern for this rule, being parsed by new RegExp() . For example:
      • // pattern will ignore all in-line comments.
      • ^import pattern will ignore all import statements.
      • ^export <(.*?)>pattern will ignore all multiple export statements.
      • class [a-zA-Z]+ implements pattern will ignore all >^import |^export <(.*?)>|class [a-zA-Z]+ implements |// pattern will ignore all the cases listed above.
    • check-strings — determines if strings should be checked, false by default.
    • check-regex — determines if regular expressions should be checked, false by default.

We’re using Delphi XE5 Architect & the version of Indy that comes with it. We have an app that sends and receives messages with different exchange partners. Some of these messages are formatted like emails, with MIME encoded parts in the body of the email. We use TIdMessage to process/decode/reconstruct the MIME parts and this works really well.

Today we started receiving errors from the TIdMessage while it is decoding the MIME parts

We’re trying to troubleshoot and see if there is a character issue?

In a hex editor, when we examine the messages, they have the text

, followed by a hex 09, which appears as a ‘.’ after the

Could this appear as an improper line break to the parser?

Also we’re considering if the content length is just too much?

With proper line breaks the messages range between 2k — 6.6k lines.

Very long lines of code in any language can be difficult to read. In order to aid in readability and maintainability many coders have developed a convention to limit lines of code to X number of characters (traditionally 80 characters).

Rule Details

This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.

Options

This rule has a number or object option:

  • «code» (default 80 ) enforces a maximum line length
  • «tabWidth» (default 4 ) specifies the character w >»comments» enforces a maximum line length for comments; defaults to value of code
  • «ignorePattern» ignores lines matching a regular expression; can only match a single line and need to be double escaped when written in YAML or JSON
  • «ignoreComments»: true ignores all trailing comments and comments on their own line
  • «ignoreTrailingComments»: true ignores only trailing comments
  • «ignoreUrls»: true ignores lines that contain a URL
  • «ignoreStrings»: true ignores lines that contain a double-quoted or single-quoted string
  • «ignoreTemplateLiterals»: true ignores lines that contain a template literal
  • «ignoreRegExpLiterals»: true ignores lines that contain a RegExp literal

Examples of incorrect code for this rule with the default < "code": 80 >option:

Examples of correct code for this rule with the default < "code": 80 >option:

tabW >Examples of incorrect code for this rule with the default < "tabWidth": 4 >option:

Examples of correct code for this rule with the default < "tabWidth": 4 >option:

comments

Examples of incorrect code for this rule with the < "comments": 65 >option:

ignoreComments

Examples of correct code for this rule with the < "ignoreComments": true >option:

ignoreTrailingComments

Examples of correct code for this rule with the < "ignoreTrailingComments": true >option:

ignoreUrls

Examples of correct code for this rule with the < "ignoreUrls": true >option:

ignoreStrings

Examples of correct code for this rule with the < "ignoreStrings": true >option:

ignoreTemplateLiterals

Examples of correct code for this rule with the < "ignoreTemplateLiterals": true >option:

ignoreRegExpLiterals

Examples of correct code for this rule with the < "ignoreRegExpLiterals": true >option:

ignorePattern

Examples of correct code for this rule with the ignorePattern option:

Оцените статью
SoftLast
Добавить комментарий