Coder Social home page Coder Social logo

deno_license_checker's Introduction

license_checker v3.2.3

ci codecov

A utility for checking license headers in the files in a directory.

Usage

Use via Deno:

deno run --allow-read https://deno.land/x/[email protected]/main.ts

Use via npx:

npx @kt3k/license-checker

Usage

Create .licenserc.json like the following:

{
  "**/*.ts": "// Copyright 2019 My Name. All rights reserved. MIT license."
}

Then run:

deno run --allow-read https://deno.land/x/[email protected]/main.ts

This checks the license lines in the files under the current directory.

.licenserc.json

You can use any glob pattern in the keys of .licenserc.json

{
  "**/*.ts": "Copyright 2019 My Name. All rights reserved. MIT license.",

  "**/*.{js,ts}": "This matches any .js and .ts files",

  "*.go": "This matches .go file in the project root, (not in subdirectories)",

  "src/**/*.ts": "This matches .ts file in `src` dir",

  "**/*.ts": [
    "You can put multiline headers like this",

    "Copyright Foo, Inc. and other Bar contributors.",

    "Permission is hereby granted, free of charge, to any person obtaining a",
    "copy of this software and associated documentation files (the",
    "\"Software\"), to deal in the Software without restriction, including",
    "without limitation the rights to use, copy, modify, merge, publish,",
    "distribute, sublicense, and/or sell copies of the Software, and to permit",
    "persons to whom the Software is furnished to do so, subject to the",
    "following conditions:",
    "..."
  ]
}

Ignore files

ignore property in the config file allows you to ignore certain files:

{
  "**/*.js": "// Copyright 2019 My Name. All rights reserved. MIT license.",

  "ignore": [
    "lib/vendor/jquery.js", // ignore this file
    "vendor/" // ignore all files under vendor
  ]
}

ignore needs to be an array, not a string.

Multiple config in .licenserc.json

You can put multiple config in .licenserc.json like the below:

[
  {
    "*.ts": "Copyright main",
    "ignore": [
      "vendor.ts"
    ]
  },
  {
    "vendor.ts": "Copyright some vendor"
  }
]

Each object in the main array is treated independently as a single config. This is useful when the some license lines overlaps the ignore pattern of the other config.

Options

Usage: license_checker.ts [options]

Options:
  -h, --help               Show this help message and exit.
  -v, --version            Show the version number and exit.
  -q, --quiet              Don't print messages except errors.
  -i, --inject             Inject license into head if missing.
  -c, --config <filename>  Specify config filename. Default is '.licenserc.json'.

API

import { checkLicense } from "https://deno.land/x/[email protected]/lib.ts";

checkLicense(configs: Config[], options: Options): Promise<boolean>

Where:

type Config = {
  ignore?: string[];
  config: Array<[string, (string | string[])]>;
};

// The tuple `[string, (string | string[])]` means
// The pair of (globPattern, license-headers)
// This checks whether license-headers exists files of globPattern.

type Options = {
  inject: boolean;
  quiet: boolean;
  cwd: string;
};

This checks the license headers according to the given config and options.

LICENSE

MIT

History

  • 2022-02-01 v3.2.0 Support url config.
  • 2022-01-22 v3.1.7 Update dependencies.
  • 2021-11-05 v3.1.6 Add npm support.
  • 2021-07-22 v3.1.4 Fix directory handling.
  • 2020-08-05 v3.0.3 Update for the new registry.
  • 2020-06-23 v2.0.1 Update for deno v1.1.0.
  • 2019-03-10 v1.5.0 Add --inject flag
  • 2019-03-10 v1.4.0 Update for deno v0.3.x
  • 2019-02-24 v1.3.0 Support Multiline copyright header #3
  • 2019-02-16 v1.2.0 Initial release

Development

See dev commands:

deno task

Run test:

deno task test

deno_license_checker's People

Contributors

dsherret avatar keroxp avatar kt3k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

deno_license_checker's Issues

Matching multiple file extensions

Hello. Seems like multiple matching is not working: "**/*.{js,ts}". I've tested with different forms of globs.

The License checker just ignores all the files and quietly passes without any outputs.

Github marketplace

Hi, I've been using the following action in my workflow smoothly, but recently it is breaking with error "Unable to resolve actions. Repository not found: kt3k/license_checker."

- name: License Checker
  uses: kt3k/[email protected]

So I tried to update it to the following based on https://github.com/marketplace/actions/license-checker

- name: License Checker
  uses: kt3k/[email protected]

but it failed with error "Error: unzip is required to install Deno". What is the correct way to use your license checker in a github workflow?

multiple allowed licences

Hi,

Is it possible to have multiple allowed licenses for same files type?
I've tried:
"/*.cs": "License 1",
"
/*.cs": "License 2"
]

but it seems to allow only last one (ie License 2)

Feature request: Multiline header support

Hi, nice tool.
Could you consider to implement support for something like this ?
Especially for licenses like GNU GPL squeezing all in one line appears just too dirty.

{
  "srcfile" : [
      "Copyright (C) 2019  Giuseppe Masino ( qub1750ul )" ,
      "This program is free software: you can redistribute it and/or modify" ,
      "it under the terms of the GNU General Public License as published by" ,
      "the Free Software Foundation, either version 3 of the License, or" ,
      "(at your option) any later version."
    ]
}

Allow Regex in licenses

For another use case, I need to allow either of the following:

// Code
// SPDX-License-Identifier: CC0-1.0

// Code

But disallow other licenses, such as:

// SPDX-License-Identifier: MIT

// Code

Is it possible to allow regex?

/(^\/+\ *SPDX-License-Identifier: CC0-1\.0.*$|^[^\/].*$)/gm

Type Error with Deno v1.6.0

Looks like this:

error: TS2794 [ERROR]: Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?
setTimeout(() => resolve(), n);
                      ~~~~~~~~~
     at https://deno.land/x/[email protected]/util.ts:36:22

     An argument for 'value' was not provided.
        new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~
        at asset:///lib.es2015.promise.d.ts:33:34

I'm not super familiar with Deno, so I'm not sure how easy a fix it but I thought I'd leave a note here.

Thanks so much for this super useful module!

Check copyright year

Hi,

is there support for copyright year check?
Some projects use start,lastmod. E.g.
Copyright 2011,2021 …

Others modify the date only on updating the file, so some files might have Copyright 2021 … while others have older years.

And a mix of both, obviously.

Need to bump version from v1.5.0

The instructions currently in the readme don't work

deno --allow-read --allow-run https://deno.land/x/[email protected]/main.ts
[7/8] Downloading https://deno.land/[email protected]/fs/denogen/cli/bundle/compiler.js:133681:17
          return new DenoError(kind, base.error());
                 ^
Uncaught Other: Import 'https://deno.land/[email protected]/fs/deno' failed: 404 Not Found
    at DenoError (js/errors.ts:22:5)
    at maybeError (js/errors.ts:33:12)
    at maybeThrowError (js/errors.ts:39:15)
    at sendSync (js/dispatch.ts:114:5)
    at fetchModuleMetaData (js/compiler.ts:137:19)
    at _resolveModule (js/compiler.ts:254:12)
    at js/compiler.ts:370:37
    at resolveModuleNames (js/compiler.ts:368:24)
    at resolveModuleNamesWorker (third_party/node_modules/typescript/lib/typescript.js:89230:127)
    at resolveModuleNamesReusingOldState (third_party/node_modules/typescript/lib/typescript.js:89473:24)

However, by fetching directly from master all works smoothly

deno --allow-read --allow-run https://raw.githubusercontent.com/kt3k/deno_license_checker/master/main.ts

Error running license check on Windows 10

Running the command below with the admin prompt I´m getting an error as follows:
deno run --unstable --allow-read https://deno.land/x/[email protected]/main.ts

deno --version
deno 1.12.1 (release, x86_64-pc-windows-msvc)
v8 9.2.230.14
typescript 4.3.5

.licenserc.json

{
    "**/*.{yml,yaml,xml,java,kt,kts,pro,swift,dart,cpp,c,js,ts,properties,gradle,sh,podspec,tsx,jsx,html,less}": [
      "Copyright",
      "MY COMPANY NAME",
      "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",
      "http://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."
      ]
}

image

cannot update dependencies

  • expandGlob has bug at 0.161.0. **/*.ts doesn't match to files in arbitrary depth dir.
  • dnt cannot generate type declaration
  • dnt can't pass the test cases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.