nikku / eslint-plugin-license-header

Rules to validate the presence of license headers in source files.
MIT License
27 stars 9 forks source link

Request for Vuejs support #4

Closed hansiemithun closed 4 years ago

hansiemithun commented 4 years ago

Plugin is great !

I used your simple example of having header.js to use as a template and it did generate the file header in all the files. Unfortunately, even App.vue extension files got added with JS comment section, so this broke the application. So, Is there any idea to support Vue files or how to tweak to get this work for the Vue project?

Vue files expect HTML way of comments like

But there will be javascript files as well along with this with / /. So, need to handle both scenarios.

And by any chance, can we have a pattern match also enabled inside header.js for copyright year to ignore 2020 strictly, some files will be 2019?

nikku commented 4 years ago

Please share a codesandbox example, i.e. a vue application that shows your usage scenario.

Please also clearly document your expected behavior (in vue HTML files) as well as the current behavior.

That gives us a solid foundation to iterate your feature request. Maybe you can even contribute JS in HTML support (vue and svelte both need that).

suterma commented 8 months ago

I would like to have this reopened. The underlying issue is probably that strictly only javascript-type files are working. When using the --fix option, working with .vue SFC components, this plugin fails quite spectacularly, even worse than with https://github.com/nikku/eslint-plugin-license-header/issues/13

@nikku Would you like me to elaborate here, or open an new issue?

In the meantime for documentation purposes, here is the eslint config I use, that exclude the rule from this plugin from .vue files. Using this, one can benefit from this great plugin for all things JS, while keeping the Vue SFC files sane.

//.eslintrc.cjs
module.exports = {
//....
    overrides: [
        {
            /** Ignore specific files for fixing with "license-header" because the fixer messes up the files */
            files: ['env.d.ts', '**/*.vue'],
            rules: {
                'license-header/header': 0,
            },
        },
    ],
    plugins: ['license-header'],
    rules: {
        'license-header/header': ['error', './resources/license-header.js'],
    },
};
nikku commented 8 months ago

@suterma The issue is closed for a reason.

If you want to contribute a test cases that reproduces the issue then we may be able to look into a fix. I agree that JS in HTML support could be neat, but I don't know about how vue eslint plug-in and svelte for a similar reason represent the HTML components.

suterma commented 8 months ago

A fix would probably not be that simple, because, from a quick code inspection, you do actually work with code statements, not the first part of a file. Thus, for supporting multiple languages / source file types, you would need to implement or use a language parser/model, instead of just a quick search/insert at the beginning of the files(s).

nikku commented 8 months ago

Thus, for supporting multiple languages / source file types, you would need to implement or use a language parser/model, instead of just a quick search/insert at the beginning of the files(s).

A great start could be a failing integration test case (using vue as an example).