Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior when using // #13

Open
stramel opened this issue Jul 21, 2022 · 4 comments
Open

Incorrect behavior when using // #13

stramel opened this issue Jul 21, 2022 · 4 comments
Labels
backlog bug Something isn't working pr welcome

Comments

@stramel
Copy link

stramel commented Jul 21, 2022

Describe the Bug

When using this header,

// Copyright Foobar. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

the fix results in incorrect behavior

Steps to Reproduce

  1. Setup eslint plugin rule to error
  2. Set license-header.js file to contain the content above.
  3. Run eslint with --fix flag

Actual Behavior

First run,

// Copyright Foobar. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0

second consecutive run,

// Copyright Foobar. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0

Expected Behavior

I would expect the license header to be properly applied.

Environment

  • Host (Browser/Node version), if applicable: Node 17.2, VSCode, Eslint 8.18
  • OS: Mac OS
  • Library version: 0.6.0
@stramel stramel added the bug Something isn't working label Jul 21, 2022
@nikku
Copy link
Owner

nikku commented Jul 21, 2022

Happy to take a PR to support multiple headers

// A
// B 
// C

Until we have that consider using a single docblock header:

/**
 * A
 * B
 */

@suterma
Copy link

suterma commented Mar 24, 2024

I can confirm this issue, ran into it today. May I suggest to document the (sole?) supported header type in the readme, until a respective PR is taken?

@nikku
Copy link
Owner

nikku commented Mar 24, 2024

@suterma Happy to take a PR documenting the limitation in a lightweight manner. Preferred of course is a PR that adds support for // license headers.

@dblock
Copy link

dblock commented Jun 4, 2024

I took a quick look, turns out it's a bit tricky. When you say /* you get a single block, but with // you get multiple lines.

[
    [
        {
            "type": "Block",
            "value": "*\n * Copyright (c) Foo Corp.\n *\n * This source code is licensed under the WTFPL license found in the\n * LICENSE file in the root of this projects source tree.\n ",
            "range": [
                0,
                164
            ],
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 6,
                    "column": 3
                }
            }
        },
        {
            "type": "Block",
            "value": "* do this ",
            "range": [
                166,
                180
            ],
            "loc": {
                "start": {
                    "line": 8,
                    "column": 0
                },
                "end": {
                    "line": 8,
                    "column": 14
                }
            }
        }
    ]
]
[
    [
        {
            "type": "Line",
            "value": "",
            "range": [
                0,
                2
            ],
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 2
                }
            }
        },
        {
            "type": "Line",
            "value": " Copyright (c) Foo Corp.",
            "range": [
                3,
                29
            ],
            "loc": {
                "start": {
                    "line": 2,
                    "column": 0
                },
                "end": {
                    "line": 2,
                    "column": 26
                }
            }
        },
        {
            "type": "Line",
            "value": "",
            "range": [
                30,
                32
            ],
            "loc": {
                "start": {
                    "line": 3,
                    "column": 0
                },
                "end": {
                    "line": 3,
                    "column": 2
                }
            }
        },
        {
            "type": "Line",
            "value": " This source code is licensed under the WTFPL license found in the",
            "range": [
                33,
                101
            ],
            "loc": {
                "start": {
                    "line": 4,
                    "column": 0
                },
                "end": {
                    "line": 4,
                    "column": 68
                }
            }
        },
        {
            "type": "Line",
            "value": " LICENSE file in the root of this projects source tree.",
            "range": [
                102,
                159
            ],
            "loc": {
                "start": {
                    "line": 5,
                    "column": 0
                },
                "end": {
                    "line": 5,
                    "column": 57
                }
            }
        },
        {
            "type": "Line",
            "value": "",
            "range": [
                160,
                162
            ],
            "loc": {
                "start": {
                    "line": 6,
                    "column": 0
                },
                "end": {
                    "line": 6,
                    "column": 2
                }
            }
        },
        {
            "type": "Block",
            "value": "* do this ",
            "range": [
                167,
                181
            ],
            "loc": {
                "start": {
                    "line": 9,
                    "column": 0
                },
                "end": {
                    "line": 9,
                    "column": 14
                }
            }
        }
    ]
]

I attempted to merge these, but couldn't get it to work, maybe that's not the right strategy? Here's a test if someone wants to beat me to iterating on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog bug Something isn't working pr welcome
Projects
None yet
Development

No branches or pull requests

4 participants