diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..06494359 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,37 @@ +## +# The MIT License (MIT) +# +# Copyright (c) 2016-2020 Mickael Jeanroy +# +# 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: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +## + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +# Indentation override for all JS under lib directory +[*.{js,ts,json,yml}] +indent_style = space +indent_size = 2 diff --git a/.eslintrc b/.eslintrc index 0be93798..dd04bfac 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,5 +26,33 @@ "object": "object" } }] - } + }, + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "env": { + "browser": true, + "es6": true, + "node": false + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": ["error", 2], + "linebreak-style": ["error", "unix"], + "quotes": ["error", "single"], + "comma-dangle": ["error", "always-multiline"], + "@typescript-eslint/no-explicit-any": 0 + } + } + ] } diff --git a/.gitattributes b/.gitattributes index 6feedd31..27f14a4b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -23,4 +23,5 @@ ## *.js text eol=lf +*.ts text eol=lf *.txt text eol=lf diff --git a/.gitignore b/.gitignore index 7553df98..cd2f309a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ /dist /npm-debug.log /package-lock.json +/.idea diff --git a/package.json b/package.json index 85dce6d4..a0bef7fe 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,8 @@ "@rollup/plugin-babel": "5.3.0", "@rollup/plugin-commonjs": "17.1.0", "@rollup/plugin-node-resolve": "11.2.0", + "@typescript-eslint/parser": "4.17.0", + "@typescript-eslint/eslint-plugin": "4.17.0", "babel-plugin-add-module-exports": "1.0.4", "eslint": "7.21.0", "eslint-config-google": "0.14.0", @@ -70,7 +72,8 @@ "rollup": "2.41.1", "rollup-plugin-prettier": "2.1.0", "rollup-plugin-strip-banner": "2.0.0", - "tmp": "0.2.1" + "tmp": "0.2.1", + "typescript": "4.2.3" }, "engines": { "node": ">=10.0.0" diff --git a/scripts/lint/index.js b/scripts/lint/index.js index 4eb18526..2e00c859 100644 --- a/scripts/lint/index.js +++ b/scripts/lint/index.js @@ -41,6 +41,11 @@ module.exports = function lint() { path.join(config.src, '**', '*.js'), path.join(config.test, '**', '*.js'), path.join(config.scripts, '**', '*.js'), + + path.join(config.root, '*.ts'), + path.join(config.src, '**', '*.ts'), + path.join(config.test, '**', '*.ts'), + path.join(config.scripts, '**', '*.ts'), ]; log.debug('Linting files: '); diff --git a/src/index.d.ts b/src/index.d.ts index 5a0e2b1e..edded30b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -22,7 +22,7 @@ * SOFTWARE. */ -import type { Plugin } from "rollup"; +import type {Plugin} from 'rollup'; export interface Person { readonly name: string, @@ -33,18 +33,17 @@ export interface Person { * Turns the person into a formatted string * @returns formatted person info */ - text: ()=> string, + text: () => string, } -export type CommentStyle = "regular" | "ignored" | "slash"; +export type CommentStyle = 'regular' | 'ignored' | 'slash'; export type Banner = string | { /** * @see {@link https://github.com/mjeanroy/rollup-plugin-license#comment-style} */ commentStyle?: CommentStyle, - content: string | (()=> string) | { - + content: string | (() => string) | { /** * File to get banner content from */ @@ -55,7 +54,7 @@ export type Banner = string | { */ encoding?: string, }, - data?: {[key: string]: string} | (()=> {[key: string]: string}), + data?: { [key: string]: string } | (() => { [key: string]: string }), }; /** @@ -97,10 +96,10 @@ export interface Dependency { * Turns the dependency into a formatted string * @returns formatted dependency license info */ - text: ()=> string, + text: () => string, } -export type ThirdPartyOutput = string | ((dependencies: Dependency[])=> void) | { +export type ThirdPartyOutput = string | ((dependencies: Dependency[]) => void) | { /** * Name of file to write licenses to @@ -120,7 +119,7 @@ export type ThirdPartyOutput = string | ((dependencies: Dependency[])=> void) | * `${dependency.name}:${dependency.version} -- ${dependency.license}`).join('\n') * ); * }, - * + * * // Lodash template that can be defined to customize report output * template: ` * <% _.forEach(dependencies, function (dependency) { %> @@ -128,10 +127,10 @@ export type ThirdPartyOutput = string | ((dependencies: Dependency[])=> void) | * <% }) %> * ` */ - template?: ((dependencies: Dependency[])=> string) | string, + template?: ((dependencies: Dependency[]) => string) | string, }; -export type ThirdParty = ((dependencies: Dependency[])=> void) | { +export type ThirdParty = ((dependencies: Dependency[]) => void) | { /** * If private dependencies should be allowed (`private: true` in package.json) * @default false @@ -144,33 +143,32 @@ export type ThirdParty = ((dependencies: Dependency[])=> void) | { * licenses, simply define the restriction such as: * @example * {allow: '(MIT OR Apache-2.0)'} - * + * * allow(dependency) { * return dependency.license === 'MIT'; * } */ - allow?: string | ((dependency: Dependency)=> boolean) | { - - /** - * Testing if the license if valid - */ - test: string | ((dependency: Dependency)=> boolean), + allow?: string | ((dependency: Dependency) => boolean) | { + /** + * Testing if the license if valid + */ + test: string | ((dependency: Dependency) => boolean), - /** - * Fail if a dependency does not specify any licenses - * @default false - */ - failOnUnlicensed?: boolean, + /** + * Fail if a dependency does not specify any licenses + * @default false + */ + failOnUnlicensed?: boolean, - /** - * Fail if a dependency specify a license that does not match given requirement - * @default false - */ - failOnViolation?: boolean, + /** + * Fail if a dependency specify a license that does not match given requirement + * @default false + */ + failOnViolation?: boolean, }, /** - * Output file for + * Output file for */ output: ThirdPartyOutput | ThirdPartyOutput[], }; @@ -205,4 +203,4 @@ export type Options = { declare function rollupPluginLicense(options: Options): Plugin; -export default rollupPluginLicense +export default rollupPluginLicense;