Skip to content

Commit

Permalink
feat: add config option to disable eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jul 5, 2023
1 parent 9606606 commit b83a19a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 9 additions & 2 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/content/pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions test/apply/eslint.js
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit b83a19a

Please sign in to comment.