From b83a19a98ec5db85b96e645916dcb65dbc64fbbd Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 5 Jul 2023 12:03:25 -0700 Subject: [PATCH] feat: add config option to disable eslint --- lib/config.js | 8 ++++++++ lib/content/index.js | 11 +++++++++-- lib/content/pkg.json | 2 +- test/apply/eslint.js | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/apply/eslint.js diff --git a/lib/config.js b/lib/config.js index 0c6333c3..e643fbab 100644 --- a/lib/config.js +++ b/lib/config.js @@ -251,6 +251,14 @@ const getFullConfig = async ({ derived.engines = pkgConfig.engines || engines } + if (!pkgConfig.eslint) { + derived.ignorePaths = derived.ignorePaths.filter(p => !p.includes('eslint')) + if (Array.isArray(pkgConfig.requiredPackages?.devDependencies)) { + pkgConfig.requiredPackages.devDependencies = + pkgConfig.requiredPackages.devDependencies.filter(p => !p.includes('eslint')) + } + } + const gitUrl = await getGitUrl(rootPkg.path) if (gitUrl) { derived.repository = { diff --git a/lib/content/index.js b/lib/content/index.js index 54af4cf6..1437e1be 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -85,7 +85,10 @@ const rootRepo = { // dir. so we might want to combine these const rootModule = { add: { - '.eslintrc.js': 'eslintrc.js', + '.eslintrc.js': { + file: 'eslintrc.js', + filter: (p) => p.config.eslint, + }, '.gitignore': 'gitignore', '.npmrc': 'npmrc', 'SECURITY.md': 'SECURITY.md', @@ -113,7 +116,10 @@ const workspaceRepo = { // Changes for each workspace but applied to the relative workspace dir const workspaceModule = { add: { - '.eslintrc.js': 'eslintrc.js', + '.eslintrc.js': { + file: 'eslintrc.js', + filter: (p) => p.config.eslint, + }, '.gitignore': 'gitignore', 'package.json': 'pkg.json', }, @@ -155,6 +161,7 @@ module.exports = { ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'], lockfile: false, codeowner: '@npm/cli-team', + eslint: true, publish: false, npm: 'npm', npx: 'npx', diff --git a/lib/content/pkg.json b/lib/content/pkg.json index 387626ef..631f5dbd 100644 --- a/lib/content/pkg.json +++ b/lib/content/pkg.json @@ -2,7 +2,7 @@ "author": "GitHub Inc.", "files": {{{ json distPaths }}}, "scripts": { - "lint": "eslint \"**/*.js\"", + "lint": "{{#if eslint}}eslint \"**/*.js\"{{else}}echo linting disabled{{/if}}", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "{{ localNpmPath }} run lint -- --fix", diff --git a/test/apply/eslint.js b/test/apply/eslint.js new file mode 100644 index 00000000..56692818 --- /dev/null +++ b/test/apply/eslint.js @@ -0,0 +1,24 @@ +const t = require('tap') +const setup = require('../setup.js') + +t.test('can disable eslint', async (t) => { + const s = await setup(t, { + package: { + templateOSS: { + eslint: false, + }, + }, + }) + await s.apply() + + const pkg = await s.readJson('package.json') + delete pkg.templateOSS // templateOSS config has eslint in it + t.notMatch(JSON.stringify(pkg), 'eslint') + + const gitignore = await s.readFile('.gitignore') + t.notMatch(gitignore, 'eslint') + + const checks = await s.check() + t.equal(checks.length, 1) + t.notMatch(checks[0].solution, 'eslint') +})