Skip to content

Commit b83a19a

Browse files
committedJul 5, 2023
feat: add config option to disable eslint
1 parent 9606606 commit b83a19a

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed
 

‎lib/config.js

+8
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ const getFullConfig = async ({
251251
derived.engines = pkgConfig.engines || engines
252252
}
253253

254+
if (!pkgConfig.eslint) {
255+
derived.ignorePaths = derived.ignorePaths.filter(p => !p.includes('eslint'))
256+
if (Array.isArray(pkgConfig.requiredPackages?.devDependencies)) {
257+
pkgConfig.requiredPackages.devDependencies =
258+
pkgConfig.requiredPackages.devDependencies.filter(p => !p.includes('eslint'))
259+
}
260+
}
261+
254262
const gitUrl = await getGitUrl(rootPkg.path)
255263
if (gitUrl) {
256264
derived.repository = {

‎lib/content/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ const rootRepo = {
8585
// dir. so we might want to combine these
8686
const rootModule = {
8787
add: {
88-
'.eslintrc.js': 'eslintrc.js',
88+
'.eslintrc.js': {
89+
file: 'eslintrc.js',
90+
filter: (p) => p.config.eslint,
91+
},
8992
'.gitignore': 'gitignore',
9093
'.npmrc': 'npmrc',
9194
'SECURITY.md': 'SECURITY.md',
@@ -113,7 +116,10 @@ const workspaceRepo = {
113116
// Changes for each workspace but applied to the relative workspace dir
114117
const workspaceModule = {
115118
add: {
116-
'.eslintrc.js': 'eslintrc.js',
119+
'.eslintrc.js': {
120+
file: 'eslintrc.js',
121+
filter: (p) => p.config.eslint,
122+
},
117123
'.gitignore': 'gitignore',
118124
'package.json': 'pkg.json',
119125
},
@@ -155,6 +161,7 @@ module.exports = {
155161
ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'],
156162
lockfile: false,
157163
codeowner: '@npm/cli-team',
164+
eslint: true,
158165
publish: false,
159166
npm: 'npm',
160167
npx: 'npx',

‎lib/content/pkg.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "GitHub Inc.",
33
"files": {{{ json distPaths }}},
44
"scripts": {
5-
"lint": "eslint \"**/*.js\"",
5+
"lint": "{{#if eslint}}eslint \"**/*.js\"{{else}}echo linting disabled{{/if}}",
66
"postlint": "template-oss-check",
77
"template-oss-apply": "template-oss-apply --force",
88
"lintfix": "{{ localNpmPath }} run lint -- --fix",

‎test/apply/eslint.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const t = require('tap')
2+
const setup = require('../setup.js')
3+
4+
t.test('can disable eslint', async (t) => {
5+
const s = await setup(t, {
6+
package: {
7+
templateOSS: {
8+
eslint: false,
9+
},
10+
},
11+
})
12+
await s.apply()
13+
14+
const pkg = await s.readJson('package.json')
15+
delete pkg.templateOSS // templateOSS config has eslint in it
16+
t.notMatch(JSON.stringify(pkg), 'eslint')
17+
18+
const gitignore = await s.readFile('.gitignore')
19+
t.notMatch(gitignore, 'eslint')
20+
21+
const checks = await s.check()
22+
t.equal(checks.length, 1)
23+
t.notMatch(checks[0].solution, 'eslint')
24+
})

0 commit comments

Comments
 (0)
Please sign in to comment.