Skip to content

Commit ea9ac8a

Browse files
authored
Unify linting across websites repos (#173)
* Copy new lint configs from dvc.org * Remove outdated workflow file and add concurrency to new one * Add new lint config and fix stylelint issues * Run fix-all * Comment out unused tests from workflow * Upgrade ESLint and Stylelint, remove deprecated stylelint-config-prettier * Run fix-all * Remove options from restyled config * Update commands and lint-staged * Add explicit prettier config argument to restyled * Run prettier on yml * Remove commented steps
1 parent 843587d commit ea9ac8a

File tree

29 files changed

+272
-169
lines changed

29 files changed

+272
-169
lines changed

.eslintrc.json

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"extends": [
33
"plugin:react/recommended",
44
"plugin:@typescript-eslint/recommended",
5-
"prettier",
65
"plugin:prettier/recommended",
76
"plugin:jsx-a11y/recommended",
8-
"plugin:json/recommended"
7+
"plugin:json/recommended",
8+
"prettier"
99
],
1010
"plugins": ["@typescript-eslint"],
1111
"parser": "@typescript-eslint/parser",
@@ -37,23 +37,18 @@
3737
"leadingUnderscore": "allow"
3838
}
3939
],
40-
"no-tabs": "error",
40+
"no-tabs": [
41+
"error",
42+
{
43+
"allowIndentationTabs": true
44+
}
45+
],
4146
"react/prop-types": "off",
42-
"@typescript-eslint/no-unused-vars": "error",
43-
"@typescript-eslint/no-var-requires": "off"
47+
"@typescript-eslint/no-unused-vars": "error"
4448
},
4549
"overrides": [
4650
{
47-
"files": [
48-
"src/utils/shared/*.?(js|ts)",
49-
"src/gatsby/**/*.js",
50-
"scripts/**/*.js",
51-
"config/**/*.js",
52-
"src/server/**/*.js",
53-
"plugins/**/*.js",
54-
"gatsby-*.js",
55-
"postcss.config.js"
56-
],
51+
"files": "**/*.js",
5752
"rules": {
5853
"@typescript-eslint/no-var-requires": "off",
5954
"@typescript-eslint/explicit-function-return-type": "off"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'Linting and Testing'
2+
3+
on: pull_request
4+
5+
concurrency:
6+
group: lint-${{ github.head_ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
run-tests:
11+
name: 'Run Tests'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install Node.js and use yarn
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '18.x'
23+
cache: 'yarn'
24+
25+
- name: Install All Dependencies
26+
run: yarn
27+
28+
- name: Check Formatting with Prettier
29+
run: yarn format-check-all
30+
31+
- name: Lint JS with ESLint
32+
run: yarn lint
33+
34+
- name: Lint CSS with Stylelint
35+
run: yarn lint-css
36+
37+
- name: Check TypeScript compilation
38+
run: yarn lint-ts

.github/workflows/lint.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx lint-staged
4+
yarn exec lint-staged

.prettierrc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@
66
"singleQuote": true,
77
"tabWidth": 2,
88
"trailingComma": "none",
9-
"useTabs": false,
10-
"overrides": [
11-
{
12-
"files": "*.css",
13-
"options": {
14-
"singleQuote": false
15-
}
16-
}
17-
]
9+
"useTabs": false
1810
}

.restyled.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
restylers:
2+
- name: prettier
3+
arguments: ['--config=./.prettierrc', '--ignore-path=./.prettierignore']
4+
include:
5+
- '**/*.css'
6+
- '**/*.js'
7+
- '**/*.json'
8+
- '**/*.jsx'
9+
- '**/*.md'
10+
- '**/*.mdx'
11+
- '**/*.ts'
12+
- '**/*.tsx'
13+
- '**/*.yaml'
14+
- '**/*.yml'

.stylelintrc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
"extends": "stylelint-config-standard",
2+
"extends": ["stylelint-config-standard"],
33
"rules": {
44
"no-descending-specificity": null,
55
"no-duplicate-selectors": null,
6-
"declaration-colon-newline-after": null,
7-
"value-list-comma-newline-after": null,
86
"property-no-unknown": [
97
true,
108
{
@@ -20,10 +18,18 @@
2018
"at-rule-no-unknown": [
2119
true,
2220
{
23-
"ignoreAtRules": ["mixin"]
21+
"ignoreAtRules": ["mixin", "tailwind", "screen"]
2422
}
2523
],
24+
"custom-property-pattern": null,
25+
"selector-id-pattern": null,
2626
"selector-class-pattern": null,
27-
"keyframes-name-pattern": null
27+
"keyframes-name-pattern": null,
28+
"function-no-unknown": [
29+
true,
30+
{
31+
"ignoreFunctions": ["a", "color-mod"]
32+
}
33+
]
2834
}
2935
}

lint-staged.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
2-
'*.ts?(x)': () => 'tsc --noEmit --skipLibCheck',
3-
'*.{js,jsx,ts,tsx}': ['prettier --write', 'eslint'],
4-
'*.md': 'prettier --write',
5-
'*.json': 'prettier --write',
6-
'*.css': 'prettier --write'
2+
'*.ts?(x)': () => 'yarn lint-ts',
3+
'*.{json,md,mdx,yml,yaml}': 'prettier --write',
4+
'*.css': ['prettier --write', 'stylelint --fix'],
5+
'*.{js,jsx,ts,tsx}': ['prettier --write', 'eslint --fix']
76
}

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
"main": "index.js",
66
"license": "MIT",
77
"scripts": {
8-
"format-staged": "pretty-quick --staged --no-restage --bail --pattern '**/*.{js,jsx,md,tsx,ts,json}'",
9-
"format-check": "prettier --check '**/*.{js,jsx,md,tsx,ts,json,css}'",
10-
"format-all": "prettier --write '**/*.{js,jsx,md,tsx,ts,json,css}'",
118
"format": "prettier --write",
12-
"lint-ts": "tsc --noEmit --skipLibCheck && eslint --ext .json,.js,.ts,.tsx .",
13-
"lint-css": "stylelint \"**/src/**/*.css\"",
9+
"format-check-all": "prettier --check \"**/*.{js,jsx,md,tsx,ts,json,css,yml,yaml}\"",
10+
"format-all": "prettier --write \"**/*.{js,jsx,md,tsx,ts,json,css,yml,yaml}\"",
11+
"lint": "eslint \"**/*.{js,jsx,ts,tsx,json}\"",
12+
"lint-fix": "eslint --fix \"**/*.{js,jsx,ts,tsx,json}\"",
13+
"lint-css": "stylelint \"packages/*/src/**/*.css\"",
14+
"lint-css-fix": "stylelint --fix \"packages/*/src/**/*.css\"",
15+
"lint-ts": "tsc --noEmit --skipLibCheck",
16+
"fix-all": "yarn format-all && yarn lint-fix && yarn lint-css-fix && yarn lint-ts",
1417
"clean": "yarn workspace example clean",
1518
"build": "yarn workspace example build",
1619
"serve": "yarn workspace example serve",
@@ -24,7 +27,7 @@
2427
"devDependencies": {
2528
"@typescript-eslint/eslint-plugin": "5.51.0",
2629
"@typescript-eslint/parser": "5.51.0",
27-
"eslint": "8.33.0",
30+
"eslint": "^8.34.0",
2831
"eslint-config-prettier": "8.6.0",
2932
"eslint-plugin-json": "3.1.0",
3033
"eslint-plugin-jsx-a11y": "6.7.1",
@@ -34,7 +37,7 @@
3437
"husky": "8.0.3",
3538
"lint-staged": "13.1.1",
3639
"prettier": "2.8.4",
37-
"stylelint": "14.16.1",
38-
"stylelint-config-standard": "29.0.0"
40+
"stylelint": "^15.1.0",
41+
"stylelint-config-standard": "30.0.1"
3942
}
4043
}

packages/gatsby-theme-iterative/gatsby-config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ module.exports = ({
3737
sentry = defaults.sentry
3838
}) => ({
3939
plugins: [
40-
{
41-
resolve: `gatsby-plugin-typescript`,
42-
options: {
43-
isTSX: true,
44-
allExtensions: true
45-
}
46-
},
4740
{
4841
resolve: 'gatsby-plugin-postcss',
4942
options: {

0 commit comments

Comments
 (0)