Skip to content

header/header eslint rule can blow away top-comments #2967

@trentm

Description

@trentm

If you add a new *.ts file to this repo with a top-comment, e.g.:

% cd opentelemetry-js-contrib/packages/host-metrics

% cat src/foo.ts
// This is my top comment.
console.log('hi');

There is, of course, a lint error about not having the license header:

% npm run lint

> @opentelemetry/[email protected] lint
> eslint . --ext .ts

/Users/trentm/src/opentelemetry-js-contrib/packages/host-metrics/src/foo.ts
  2:1  error  header should be a block comment  header/header

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

npm error Lifecycle script `lint` failed with error:
npm error code 1

If you run lint:fix to add it, any existing top-comment is blown away:

% npm run lint:fix
...

% cat src/foo.ts
/*
 * Copyright The OpenTelemetry Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * 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.
 */
console.log('hi');

Here are some recent cases where we noticed this:

And I've noticed this in the past as well. I speculate that some (possibly very useful, explanatory) top-comments for some files added to the repo have been lost due to this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p4Bugs and spec inconsistencies which do not fall into a higher prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions