eslint: spaced-comment exceptions not working

ESLint Version: 3.12.2 Node Version: 6.6.0 npm Version: 3.10.8

What parser (default, Babel-ESLint, etc.) are you using? Using eslint directly via VSCode

Please show your full configuration:

root: true

env:
  es6: true

extends:
  - standard
  - standard-react

plugins:
  - import
  - react
  - babel

parser: babel-eslint

settings:
  import/resolve:
    extensions: [ .es6, .js, .jsx ]
  import/resolver: webpack
  import/ignore:
    - lodash
    - isomorphic-fetch
    - jquery
    - accounting
    - moment
    - normalizr
    - react
    - react-router
    - redux
  import/parser: babel-eslint

rules:
  import/no-unresolved: [0, { commonjs: true, amd: true }]
  sort-imports:
    - 0
    - ignoreCase: true
      ignoreMemberSort: false
      memberSyntaxSortOrder:
      - all
      - single
      - multiple
      - none

  # overrides for standard, standard-react
  react/prefer-stateless-function: error
  react/display-name: error
  # maybe in the future
  # react/require-optimization: error
  # disabling sort-prop-types - sorting by argument order is much easier to follow
  # react/sort-prop-types: error
  react/jsx-wrap-multilines: error
  react/self-closing-comp: error

  # overrides for esline-plugin-react
  react/prop-types: [ 2, {
    skipUndeclared: true,
    ignore: [ setTitle, addStylesheet, setDescription ]
  }]

  # enforce code quality and predictability
  eqeqeq: error
  strict: error

  no-cond-assign: [error, always]
  no-console: error
  no-control-regex: error
  no-debugger: error
  no-dupe-args: error
  no-dupe-keys: error
  no-empty-character-class: 2
  no-empty: 2
  no-ex-assign: 2
  no-extra-boolean-cast: 2
  no-extra-parens: 2
  no-extra-semi: 2
  no-func-assign: 2
  no-inner-declarations: [2, both]
  no-invalid-regexp: 2
  no-irregular-whitespace: 2
  no-negated-in-lhs: 2
  no-obj-calls: 2
  no-regex-spaces: 2
  no-sparse-arrays: 2
  no-unexpected-multiline: 2
  no-unreachable: 2
  no-unmodified-loop-condition: error
  use-isnan: 2

  # don't require jsdoc
  require-jsdoc:
    - 2
    - require:
        FunctionDeclaration: false
        ClassDeclaration: false
        MethodDefinition: false

  # but if jsdoc is specified, make sure it's valid
  valid-jsdoc:
    - 2
    - requireReturn: false
      requireReturnType: true
      requireReturnDescription: false
      requireParamDescription: false
      prefer:
        return: returns
  valid-typeof: 2

  accessor-pairs: 0
  block-scoped-var: 2
  complexity: [2, 6]
  consistent-return: 2
  curly: 2
  default-case: 2
  dot-location: [2, property]
  dot-notation: [2, { allowKeywords: false }]
  guard-for-in: 2
  no-alert: 1
  no-caller: 2
  no-case-declarations: 2
  no-div-regex: 2
  no-duplicate-imports: 0
  no-else-return: 2
  no-labels: error
  no-empty-pattern: 2
  no-eq-null: 2
  no-eval: 2
  no-extend-native: 2
  no-extra-bind: 2
  no-fallthrough: 2
  no-floating-decimal: 2
  no-implicit-coercion: 2
  no-implied-eval: 2
  no-invalid-this: 0 # can't enable - https://github.com/babel/babel-eslint/issues/401
  no-iterator: 2
  no-lone-blocks: 2
  no-loop-func: 2
  no-magic-numbers:
    - 0
    - enforceConst: true
      detectObjects: true
      ignoreArrayIndexes: false
      # Only ignore magic numbers that don't have "special meaning". Magic
      # numbers that have special meaning must be named, e.g.,
      # `const # MINUTES_PER_HOUR = 60;`. Just because a number is "ignored"
      # here does not mean that it does not have special meaning, e.g., some 3rd
      # party library may use `0` to indicate a "does not exist" error code.  In
      # this case you should still do, e.g., `const E_NOT_EXIST = 0;`, even
      # though `0` is ignored.
      ignore:
        - 0 # charAt(0), arr[0] - common idioms
        - -1 # -1 === ''.indexOf('thing') - idiomatic error code
        #- 1 # 1 *has* special meaning, so give it a name, do not un-ignore
  no-multi-spaces: 2
  no-multi-str: 2
  no-native-reassign: 2
  no-new-func: 2
  no-new-wrappers: 2
  no-new: 2
  no-octal-escape: 2
  no-octal: 2
  no-param-reassign: 2
  no-process-env: 2
  no-proto: 2
  no-redeclare: 2
  no-return-assign: 2
  no-script-url: 2
  no-self-compare: 2
  no-sequences: 2
  no-throw-literal: 2
  no-unused-expressions: 2
  no-useless-call: 2
  no-useless-concat: 2
  no-void: 2
  no-warning-comments: 1
  no-with: 2
  radix: [2, always]
  vars-on-top: 2
  wrap-iife: [2, inside]
  yoda: [2, never]
  no-undef-init: 2
  init-declarations: [2, always]
  no-undef: 2
  no-undefined: 2
  no-catch-shadow: 2
  no-delete-var: 2
  no-label-var: 2
  no-shadow: 2
  no-shadow-restricted-names: 2
  no-unused-vars:
    - 2
    - vars: all
      varsIgnorePattern: ^_
      args: after-used
      argsIgnorePattern: ^(_|reject|resolve)
  no-use-before-define: 2

  # nodejs and commonjs specific
  # callback-return: 2
  global-require: 2
  handle-callback-err: [2, ^(err|error)$]
  no-mixed-requires: [2, { grouping: true }]
  no-new-require: 2
  no-path-concat: 2
  no-process-exit: 2

  # enforce consistency
  comma-dangle: [2, always-multiline]
  array-bracket-spacing: [2, always]
  block-spacing: [2, always]
  brace-style: [2, 1tbs, { allowSingleLine: true }]
  camelcase: 2
  comma-style: [2, last]
  comma-spacing: [2, { before: false, after: true }]
  computed-property-spacing: [2, never]
  consistent-this: [2, self]
  eol-last: 2
  linebreak-style: [2, unix]
  func-names: 2

  # func-style needs an option to allow generators be function
  # declarations; or there should be a `gen-style`
  func-style: [2, declaration, { allowArrowFunctions: true }]
  # id-length: [error, { min: 3, max 32, properties: never, exceptions: [e, _, __, _0, _1, _2, id] }]
  id-match:
    - 2
    - ^(_[0-9]?|[A-Z_]{3,}|[A-Za-z]+[0-9]*|[$])$
    - properties: false
  indent: [2, 2, { SwitchCase: 1 }]
  jsx-quotes: [error, prefer-single]
  lines-around-comment:
    - 2
    - beforeBlockComment: false
      beforeLineComment: false
      allowBlockStart: true
      allowBlockEnd: false
      allowObjectStart: true
      allowObjectEnd: false
      allowArrayStart: true
      allowArrayEnd: false
  max-depth: [2, 3]
  max-len: [1, 100, 4, { ignoreUrls: true, ignorePattern: "\\s*<" }]
  max-nested-callbacks: [2, 3]
  max-statements: [2, 20]
  new-cap: [2, { capIsNew: true, newIsCap: true, capIsNewExceptions: [ "Radium" ] }]
  new-parens: 2
  newline-after-var: [1, always]
  no-array-constructor: 2
  no-bitwise: 2
  no-inline-comments: 0
  no-lonely-if: 2
  no-mixed-spaces-and-tabs: 2
  no-multiple-empty-lines: [2, { max: 1, maxEOF: 1, maxBOF: 0 }]
  no-negated-condition: 2
  no-nested-ternary: 2
  no-new-object: 2
  no-plusplus: [2, { allowForLoopAfterthoughts: true }]
  no-spaced-func: 2
  no-trailing-spaces: [2, { "skipBlankLines": false }]
  no-underscore-dangle: 2
  no-unneeded-ternary: [2, { defaultAssignment: false }]
  object-curly-spacing: [2, always]
  one-var: [2, never]
  operator-assignment: [2, never]
  operator-linebreak: [2, before, { overrides: { =: after }}]
  padded-blocks: [2, never]
  quote-props: [2, consistent-as-needed]
  quotes: [error, single, { avoidEscape: true, allowTemplateLiterals: false }]
  semi-spacing: [2, { before: false, after: true }]
  semi: [2, always]
  sort-vars: 2
  keyword-spacing:
    - error
    - before: true
      after: true
  space-before-blocks: [2, always]
  space-before-function-paren: [2, never]
  space-in-parens: [2, never]
  space-infix-ops: 2
  space-unary-ops: [2, { words: true, nonwords: false }]
  spaced-comment:
    - 1
    - never
    -
      line:
        markers: [ ]
        exceptions: [ "*" ]
      block:
        balanced: false
        markers: [ ]
        exceptions: [ "*" ]
  wrap-regex: 2

  arrow-body-style: [2, as-needed]
  arrow-parens: [2, always]
  arrow-spacing: [2, { before: true, after: true }]
  no-confusing-arrow: error
  no-constant-condition: [error, { checkLoops: false }]
  constructor-super: 2
  no-class-assign: 2
  no-const-assign: 2
  no-dupe-class-members: 2
  no-this-before-super: 2
  no-var: 2
  object-shorthand: [2, always]
  prefer-arrow-callback: 2
  prefer-const: 2
  prefer-reflect: 2
  prefer-spread: 2
  prefer-template: 2

  # generator functions
  require-yield: error
  generator-star-spacing: [error, { before: false, after: true }]
  yield-star-spacing: [error, { before: false, after: true }]

What did you do? Please include the actual source code causing the issue.

      {/* jsx comment */}

What did you expect to happen? I’m trying to ensure that comments with /* allow a space */ when inline or block. However, comments like //do not have a space.

What actually happened? Please include the actual, raw output from ESLint. Eslint complains that a space isn’t permitted here. I’ve tried a variety of different marker and exceptions, but I cannot seem to get this working properly. Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (12 by maintainers)

Most upvoted comments

@oojacoboo A line comment is // this, a block comment is /* this */ (whether it is used “inline” or not).

Oops, you’re right. It seems like the “exceptions” array is accepting a list of strings to exactly match the comment, not regex patterns. So you could put this in your config to prevent that comment from being reported:

"spaced-comment": ["error", "always", { "exceptions": ["TODO: this is a test"] }]

But that seems like a very non-useful option if it requires you to know exactly what your comments will say when configuring the rule.

Okay, thank you. So, yes, separate options for the spacing for block/line comments is exactly what’s needed.

Is a single line comment that uses /* to open and */ to close the comment a “line comment” or a “block comment”?

Hi, thanks for the report. However, this appears to be working as intended. It looks like the spaced-comment docs mention that exceptions are ignored if the first option is “never”.