Skip to content

Commit 253d342

Browse files
authored
Lint all JavaScript and TypeScript files (#1294)
* Lint all JavaScript and TypeScript files * Fix repository-wide lint violations --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 58cbcd3 commit 253d342

9 files changed

Lines changed: 72 additions & 41 deletions

File tree

eslint.config.mjs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import github from 'eslint-plugin-github'
22
import globals from 'globals'
33

4-
const {browser, internal, react, recommended} = github.getFlatConfigs()
4+
const {browser, internal, react, recommended, typescript} = github.getFlatConfigs()
5+
const javascriptFiles = ['**/*.{js,mjs,cjs,jsx}']
6+
const typescriptFiles = ['**/*.{ts,mts,cts,tsx}']
7+
const configFiles = ['**/*.config.{js,mjs,cjs,ts,mts,cts}']
8+
const declarationFiles = ['**/*.d.{ts,mts,cts}']
59
const nodeFiles = ['tests/**/*.js', 'lib/octicons_node/{index.js,tests/**/*.js}']
6-
const reactFiles = ['lib/octicons_{react,styled}/{pages,script,src}/**/*.{js,mjs}']
7-
const lintFiles = [...nodeFiles, ...reactFiles]
10+
const reactFiles = ['lib/octicons_{react,styled}/{pages,script,src,ts-tests}/**/*.{js,mjs,jsx,ts,tsx}']
11+
const testFiles = ['**/{__tests__,tests,ts-tests}/**/*.{js,mjs,cjs,jsx,ts,tsx}']
12+
const typeTestFiles = ['**/ts-tests/**/*.{ts,mts,cts,tsx}']
13+
const lintFiles = [...javascriptFiles, ...typescriptFiles]
814

915
export default [
10-
{
11-
ignores: ['lib/octicons_react/src/__generated__/**', 'lib/octicons_styled/src/__generated__/**'],
12-
},
16+
{ignores: ['**/__generated__/**', '**/{build,coverage,dist}/**', '**/.{cache,next}/**', 'public/**', 'vendor/**']},
1317
{...recommended, files: lintFiles},
18+
...typescript.map(config => ({...config, files: typescriptFiles})),
1419
{...internal, files: nodeFiles},
1520
{...browser, files: reactFiles},
1621
{...react, files: reactFiles},
@@ -42,6 +47,34 @@ export default [
4247
'import/no-commonjs': 'off',
4348
},
4449
},
50+
{
51+
files: configFiles,
52+
rules: {
53+
'github/filenames-match-regex': 'off',
54+
'import/extensions': 'off',
55+
'import/no-commonjs': 'off',
56+
'import/no-named-as-default': 'off',
57+
'import/no-unresolved': 'off',
58+
},
59+
},
60+
{
61+
files: testFiles,
62+
rules: {
63+
'import/extensions': 'off',
64+
'import/no-commonjs': 'off',
65+
'import/no-dynamic-require': 'off',
66+
'import/no-named-as-default': 'off',
67+
'import/no-namespace': 'off',
68+
},
69+
},
70+
{
71+
files: declarationFiles,
72+
rules: {
73+
'@typescript-eslint/no-explicit-any': 'off',
74+
'import/extensions': 'off',
75+
'import/no-namespace': 'off',
76+
},
77+
},
4578
{
4679
files: reactFiles,
4780
rules: {
@@ -52,7 +85,7 @@ export default [
5285
},
5386
},
5487
{
55-
files: ['lib/octicons_{react,styled}/script/**/*.js'],
88+
files: ['**/script/**/*.js'],
5689
rules: {
5790
'import/extensions': 'off',
5891
'import/no-commonjs': 'off',
@@ -73,4 +106,11 @@ export default [
73106
'i18n-text/no-en': 'off',
74107
},
75108
},
109+
{
110+
files: typeTestFiles,
111+
rules: {
112+
'@typescript-eslint/no-unused-vars': 'off',
113+
'no-unused-vars': 'off',
114+
},
115+
},
76116
]

lib/octicons_react/next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const nextConfig = {
33
reactStrictMode: true,
44
transpilePackages: ['@primer/components'],
5-
pageExtensions: ['js', 'jsx', 'mjs', 'ts', 'tsx'],
5+
pageExtensions: ['js', 'jsx', 'mjs', 'ts', 'tsx']
66
}
77

88
export default nextConfig

lib/octicons_react/src/index.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// eslint-disable-next-line import/no-namespace
21
import * as React from 'react'
32

4-
// eslint-disable-next-line prettier/prettier
53
import {Icon} from './__generated__/icons/index.js'
64

75
type Size = 'small' | 'medium' | 'large'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"scripts": {
1414
"build": "script/build.js --input icons/**/*.svg --output lib/build/data.json",
1515
"changeset:version": "changeset version && script/version lib/octicons_node/package.json",
16-
"lint": "eslint tests",
16+
"lint": "eslint .",
1717
"svgo": "svgo icons --config svgo.config.js",
1818
"test": "vitest",
1919
"version": "script/version"

script/build.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
/* eslint-env node */
32
const fs = require('fs-extra')
43
const path = require('path')
54
const globby = require('globby')
@@ -20,20 +19,19 @@ const {argv} = yargs
2019
alias: 'i',
2120
type: 'array',
2221
demandOption: true,
23-
describe: 'Input SVG files'
22+
describe: 'Input SVG files',
2423
})
2524
.option('output', {
2625
alias: 'o',
2726
type: 'string',
28-
describe: 'Output JSON file. Defaults to stdout if no output file is provided.'
27+
describe: 'Output JSON file. Defaults to stdout if no output file is provided.',
2928
})
3029

3130
// The `argv.input` array could contain globs (e.g. "**/*.svg").
3231
const filepaths = globby.sync(argv.input)
3332
const svgFilepaths = filepaths.filter(filepath => path.parse(filepath).ext === '.svg')
3433

3534
if (svgFilepaths.length === 0) {
36-
// eslint-disable-next-line no-console
3735
console.error('No input SVG file(s) found')
3836
process.exit(1)
3937
}
@@ -47,7 +45,7 @@ const icons = svgFilepaths.map(filepath => {
4745

4846
if (!filenamePattern.test(filename)) {
4947
throw new Error(
50-
`${filename}: Invalid filename. Please append the height of the SVG to the end of the filename (e.g. alert-16.svg).`
48+
`${filename}: Invalid filename. Please append the height of the SVG to the end of the filename (e.g. alert-16.svg).`,
5149
)
5250
}
5351

@@ -59,7 +57,7 @@ const icons = svgFilepaths.map(filepath => {
5957
const svgViewBox = svgElement.attr('viewBox')
6058
const svgPath = trimNewlines(svgElement.html()).trim()
6159
const ast = parseSync(svg, {
62-
camelcase: true
60+
camelcase: true,
6361
})
6462

6563
if (!svgWidth) {
@@ -82,7 +80,7 @@ const icons = svgFilepaths.map(filepath => {
8280

8381
if (!viewBoxPattern.test(svgViewBox)) {
8482
throw new Error(
85-
`${filename}: Invalid viewBox attribute. The viewBox attribute should be in the following format: "0 0 <width> <height>"`
83+
`${filename}: Invalid viewBox attribute. The viewBox attribute should be in the following format: "0 0 <width> <height>"`,
8684
)
8785
}
8886

@@ -102,10 +100,9 @@ const icons = svgFilepaths.map(filepath => {
102100
width: svgWidth,
103101
height: svgHeight,
104102
path: svgPath,
105-
ast
103+
ast,
106104
}
107105
} catch (error) {
108-
// eslint-disable-next-line no-console
109106
console.error(error)
110107
// Instead of exiting immediately, we set exitCode to 1 and continue
111108
// iterating through the rest of the SVGs. This allows us to identify all
@@ -132,12 +129,12 @@ const iconsByName = icons.reduce(
132129
[icon.height]: {
133130
width: icon.width,
134131
path: icon.path,
135-
ast: icon.ast
136-
}
137-
}
138-
}
132+
ast: icon.ast,
133+
},
134+
},
135+
},
139136
}),
140-
{}
137+
{},
141138
)
142139

143140
if (argv.output) {

svgo.config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
/* eslint-disable import/no-commonjs,filenames/match-regex */
2-
31
module.exports = {
42
multipass: true,
53
plugins: [
64
{
75
name: 'preset-default',
86
params: {
97
overrides: {
10-
removeViewBox: false
11-
}
12-
}
8+
removeViewBox: false,
9+
},
10+
},
1311
},
1412
'removeStyleElement',
1513
{
1614
name: 'removeAttrs',
1715
params: {
18-
attrs: ['xmlns:xlink', 'id', 'class', 'data-name', 'fill', 'transform', 'href', 'clip-path', 'clip-rule']
19-
}
20-
}
21-
]
16+
attrs: ['xmlns:xlink', 'id', 'class', 'data-name', 'fill', 'transform', 'href', 'clip-path', 'clip-rule'],
17+
},
18+
},
19+
],
2220
}

tests/build.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-commonjs */
21
const path = require('path')
32
const execa = require('execa')
43

tests/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-commonjs */
21
/* eslint-disable i18n-text/no-en */
32

43
const fs = require('fs-extra')

vitest.config.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export default defineConfig({
77
test: {
88
name: 'octicons',
99
globals: true,
10-
include: ['tests/*.js']
11-
}
10+
include: ['tests/*.js'],
11+
},
1212
},
1313
'./lib/octicons_node/vitest.config.mjs',
1414
'./lib/octicons_react/vitest.config.mjs',
1515
'./lib/octicons_react/vitest.browser.config.mjs',
16-
'./lib/octicons_styled/vitest.config.mjs'
17-
]
18-
}
16+
'./lib/octicons_styled/vitest.config.mjs',
17+
],
18+
},
1919
})

0 commit comments

Comments
 (0)