Skip to content

Commit

Permalink
chore: remove (deprecated) eslint-config-google
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed May 24, 2024
1 parent a7c455f commit 0ba031f
Show file tree
Hide file tree
Showing 34 changed files with 231 additions and 178 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
##

/dist
/test/fixtures
28 changes: 26 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
{
"extends": [
"eslint:recommended",
"google"
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 2020
"ecmaVersion": "latest"
},
"env": {
"es6": true,
"node": true
},
"rules": {
"max-len": [2, 150, 2],

"import/prefer-default-export": "off",

"import/no-extraneous-dependencies": ["error", {
"devDependencies": [
"scripts/**/*.js",
"test/**/*.js",
"gulpfile.js"
]
}],

"operator-linebreak": "off",
"consistent-return": "off",
"no-underscore-dangle": "off",
"no-plusplus": "off",
"quote-props": ["error", "consistent-as-needed"],
"no-use-before-define": ["error", {
"functions": false,
"classes": true,
"variables": true,
"allowNamedExports": true
}],

"no-console": [0],

"valid-jsdoc": [2, {
"requireReturn": true,
"requireParamDescription": true,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
"@rollup/plugin-virtual": "3.0.2",
"@typescript-eslint/eslint-plugin": "7.10.0",
"@typescript-eslint/parser": "7.10.0",
"ansi-colors": "4.1.3",
"babel-plugin-add-module-exports": "1.0.4",
"eslint": "8.57.0",
"eslint-config-google": "0.14.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.29.1",
"fancy-log": "2.0.0",
"fs-extra": "11.2.0",
"globalthis": "1.0.4",
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const rollupConfig = require('./rollup.config');
const config = require('../config');

module.exports = gulp.series(
buildOutput,
copyTypings,
buildOutput,
copyTypings,
);

// eslint-disable-next-line require-jsdoc
Expand Down
1 change: 1 addition & 0 deletions scripts/build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const prettier = require('rollup-plugin-prettier');

const config = require('../config');
const pkg = require('../../package.json');

const license = fs.readFileSync(path.join(config.root, 'LICENSE'), 'utf-8');

module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions scripts/changelog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const conventionalChangelog = require('gulp-conventional-changelog');
const config = require('../config');

module.exports = function changelog() {
const changelog = path.join(config.root, 'CHANGELOG.md');
return gulp.src(changelog, {buffer: false})
.pipe(conventionalChangelog({releaseCount: 0}))
.pipe(gulp.dest(config.root));
const changelogFile = path.join(config.root, 'CHANGELOG.md');
return gulp.src(changelogFile, { buffer: false })
.pipe(conventionalChangelog({ releaseCount: 0 }))
.pipe(gulp.dest(config.root));
};
2 changes: 1 addition & 1 deletion scripts/clean/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

const {rimraf} = require('rimraf');
const { rimraf } = require('rimraf');
const config = require('../config');

module.exports = function clean() {
Expand Down
1 change: 1 addition & 0 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

const path = require('node:path');

const ROOT = path.join(__dirname, '..');

module.exports = {
Expand Down
6 changes: 5 additions & 1 deletion scripts/lint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ module.exports = function lint() {
log.debug(` ${input}`)
));

const {ESLint} = require('eslint');
// eslint-disable-next-line global-require
const { ESLint } = require('eslint');

// eslint-disable-next-line global-require
const fancyLog = require('fancy-log');

const eslint = new ESLint({
errorOnUnmatchedPattern: false,
});
Expand Down
6 changes: 3 additions & 3 deletions scripts/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function bumpVersion(type) {
*/
function prepareNextRelease() {
return run(`git rm -r "${config.dist}"`).then(() => (
run(`git commit -m 'release: prepare next release'`)
run("git commit -m 'release: prepare next release'")
));
}

Expand All @@ -86,8 +86,8 @@ function createReleaseTask(level) {
}

return gulp.series(
doRelease,
prepareNextRelease,
doRelease,
prepareNextRelease,
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/

import _ from 'lodash';
import {EOL} from './eol.js';
import {Person} from './person.js';
import { EOL } from './eol';
import { Person } from './person';

/**
* Dependency structure.
Expand Down Expand Up @@ -95,9 +95,9 @@ export class Dependency {
}

if (this.contributors.length > 0) {
lines.push(`Contributors:`);
lines.push('Contributors:');
lines.push(
...this.contributors.map((contributor) => ` ${contributor.text()}`),
...this.contributors.map((contributor) => ` ${contributor.text()}`),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/generate-block-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export function generateBlockComment(text, commentStyle) {

if (commentStyle) {
options.style = new commenting.Style(
commentStyle.body,
commentStyle.start,
commentStyle.end,
commentStyle.body,
commentStyle.start,
commentStyle.end,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

import type {Plugin} from 'rollup';
import type { Plugin } from 'rollup';

type FilePath = string;
type FileEncoding = string;
Expand Down Expand Up @@ -198,7 +198,7 @@ type SpdxId = string;
/**
* Function checking dependency license validity.
*/
type ThirdPartyDependencyValidatorFn = (Dependency: Dependency) => boolean;
type ThirdPartyDependencyValidatorFn = (dependency: Dependency) => boolean;

type ThirdPartyValidator = SpdxId | ThirdPartyDependencyValidatorFn;

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

import {licensePlugin} from './license-plugin.js';
import { licensePlugin } from './license-plugin';

/**
* Create rollup plugin compatible with rollup >= 1.0.0
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function rollupPluginLicense(options = {}) {
}

plugin.scanDependencies(
dependencies,
dependencies,
);

return plugin.prependBanner(code, outputOptions.sourcemap !== false);
Expand Down
10 changes: 5 additions & 5 deletions src/license-plugin-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/

import _ from 'lodash';
import {PLUGIN_NAME} from './license-plugin-name.js';
import {validators} from './schema-validators.js';
import {validateSchema} from './schema-validator.js';
import {formatPath} from './format-path.js';
import { PLUGIN_NAME } from './license-plugin-name';
import { validators } from './schema-validators';
import { validateSchema } from './schema-validator';
import { formatPath } from './format-path';

/**
* The option object schema.
Expand Down Expand Up @@ -152,7 +152,7 @@ function validateOptions(options) {

if (messages.length > 0) {
throw new Error(
`[${PLUGIN_NAME}] -- Error during validation of option object: ${messages.join(' ; ')}`,
`[${PLUGIN_NAME}] -- Error during validation of option object: ${messages.join(' ; ')}`,
);
}
}
Expand Down
53 changes: 31 additions & 22 deletions src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@

import fs from 'fs';
import path from 'path';
import {mkdirp} from 'mkdirp';
import { mkdirp } from 'mkdirp';
import _ from 'lodash';
import moment from 'moment';
import MagicString from 'magic-string';
import packageNameRegex from 'package-name-regex';

import {Dependency} from './dependency.js';
import {generateBlockComment} from './generate-block-comment.js';
import {licensePluginOptions} from './license-plugin-option.js';
import {licenseValidator} from './license-validator';
import {readFile} from './read-file';
import {PLUGIN_NAME} from './license-plugin-name.js';
import {EOL} from './eol.js';
import { Dependency } from './dependency';
import { generateBlockComment } from './generate-block-comment';
import { licensePluginOptions } from './license-plugin-option';
import { licenseValidator } from './license-validator';
import { readFile } from './read-file';
import { PLUGIN_NAME } from './license-plugin-name';
import { EOL } from './eol';

/**
* Pre-Defined comment style:
Expand Down Expand Up @@ -103,9 +103,11 @@ class LicensePlugin {
this._options = options;
this._cwd = this._options.cwd || process.cwd();
this._dependencies = new Map();
this._pkg = require(path.join(this._cwd, 'package.json'));
this._debug = this._options.debug || false;

// eslint-disable-next-line import/no-dynamic-require, global-require
this._pkg = require(path.join(this._cwd, 'package.json'));

// SourceMap can now be disable/enable on the plugin.
this._sourcemap = this._options.sourcemap !== false;

Expand Down Expand Up @@ -139,6 +141,7 @@ class LicensePlugin {
*/
scanDependency(id) {
if (id.startsWith('\0')) {
// eslint-disable-next-line no-param-reassign
id = id.replace(/^\0/, '');
this.debug(`scanning internal module ${id}`);
}
Expand Down Expand Up @@ -186,15 +189,14 @@ class LicensePlugin {

// Read `package.json` file
const pkgJson = JSON.parse(
fs.readFileSync(pkgPath, 'utf-8'),
fs.readFileSync(pkgPath, 'utf-8'),
);

// We are probably in a package.json specifying the type of package (module, cjs).
// Nevertheless, if the package name is not defined, we must not use this `package.json` descriptor.
const license = pkgJson.license || pkgJson.licenses;
const hasLicense = license && license.length > 0;
const name = pkgJson.name;
const version = pkgJson.version;
const { name, version } = pkgJson;
const isValidPackageName = name && packageNameRegex.test(name);
if ((isValidPackageName && version) || hasLicense) {
// We found it!
Expand Down Expand Up @@ -270,7 +272,7 @@ class LicensePlugin {
// will be used to generate the sourcemap.
const magicString = new MagicString(code);

const banner = this._options.banner;
const { banner } = this._options;
const content = this._readBanner(banner);
if (content) {
magicString.prepend(EOL);
Expand Down Expand Up @@ -318,7 +320,7 @@ class LicensePlugin {
* @return {void}
*/
scanThirdParties() {
const thirdParty = this._options.thirdParty;
const { thirdParty } = this._options;
if (!thirdParty) {
return;
}
Expand All @@ -333,12 +335,12 @@ class LicensePlugin {
return;
}

const allow = thirdParty.allow;
const { allow, output } = thirdParty;

if (allow) {
this._scanLicenseViolations(outputDependencies, allow);
}

const output = thirdParty.output;
if (output) {
this._exportThirdParties(outputDependencies, output);
}
Expand Down Expand Up @@ -398,7 +400,7 @@ class LicensePlugin {
throw new Error(`[${this.name}] -- Cannot find banner content, please specify an inline content, or a path to a file`);
}

const file = content.file;
const { file } = content;
const encoding = content.encoding || 'utf-8';

this.debug(`prepend banner from file: ${file}`);
Expand Down Expand Up @@ -434,7 +436,13 @@ class LicensePlugin {
const pkg = this._pkg;
const dependencies = [...this._dependencies.values()];
const data = banner.data ? _.result(banner, 'data') : {};
const text = tmpl({_, moment, pkg, dependencies, data});
const text = tmpl({
_,
moment,
pkg,
dependencies,
data,
});

// Compute comment style to use.
const style = _.has(banner, 'commentStyle') ? banner.commentStyle : computeDefaultCommentStyle(text);
Expand Down Expand Up @@ -523,9 +531,10 @@ class LicensePlugin {
* @return {void}
*/
_handleLicenseViolation(dependency, fail) {
const message =
const message = (
`Dependency "${dependency.name}" has a license (${dependency.license}) which is not compatible with ` +
`requirement, looks like a license violation to fix.`;
'requirement, looks like a license violation to fix.'
);

if (!fail) {
this.warn(message);
Expand Down Expand Up @@ -565,7 +574,7 @@ class LicensePlugin {
// Default is to export to given file.

// Allow custom formatting of output using given template option.
const template = _.isString(output.template) ? (dependencies) => _.template(output.template)({dependencies, _, moment}) : output.template;
const template = _.isString(output.template) ? (dependencies) => _.template(output.template)({ dependencies, _, moment }) : output.template;
const defaultTemplate = (dependencies) => (
dependencies.length === 0 ? 'No third parties dependencies' : dependencies.map((d) => d.text()).join(`${EOL}${EOL}---${EOL}${EOL}`)
);
Expand Down Expand Up @@ -596,6 +605,6 @@ class LicensePlugin {
*/
export function licensePlugin(options) {
return new LicensePlugin(
licensePluginOptions(options),
licensePluginOptions(options),
);
}
Loading

0 comments on commit 0ba031f

Please sign in to comment.