Skip to content

Commit

Permalink
Merge branch 'main' of github.com:joelcox22/lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joelcox22 committed Apr 27, 2024
2 parents a01c128 + 8014799 commit 419a0d8
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: yarn
run: yarn
- name: release
run: yarn workspaces run semantic-release -e semantic-release-monorepo
run: yarn release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.tgz
tsconfig.tsbuildinfo
3 changes: 3 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const config = [
'react/jsx-no-literals': 0,
'react/jsx-no-bind': [1, { allowArrowFunctions: true }],
'react/jsx-filename-extension': [2, { extensions: ['.jsx', '.tsx'] }],
'react/destructuring-assignment': 0,
'react/no-unused-prop-types': 1,
'react/jsx-sort-props': 0,
},
languageOptions: {
parserOptions: {
Expand Down
10 changes: 9 additions & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@joelbot/eslint-config",
"version": "0.0.0",
"private": true,
"private": false,
"main": "index.js",
"description": "A personal opinionated eslint configuration.",
"author": "Joel Cox <[email protected]>",
Expand Down Expand Up @@ -31,5 +31,13 @@
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"publishConfig": {
"access": "public"
},
"release": {
"branches": [
"main"
]
}
}
4 changes: 2 additions & 2 deletions packages/lint/config/force-devDependencies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as root from 'app-root-path';
import root from 'app-root-path';
import * as path from 'path';
import * as util from '../util.js';

Expand All @@ -16,7 +16,7 @@ export default function configureForcedDevDependencies() {
} else {
debug("skipping @joelbot/* dependencies because it looks like you're working on @joelbot/lint repo");
}
const optional = ['semantic-release', 'typescript', 'jest', '@types/jest'];
const optional = ['semantic-release', 'typescript', 'jest', '@types/jest', 'typescript'];
Object.entries(force).forEach(([name, version]) => {
if (packageJson.dependencies[name]) {
delete packageJson.dependencies[name];
Expand Down
9 changes: 9 additions & 0 deletions packages/lint/config/gitignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as util from '../util.js';
export const name = 'gitignore';

export default function configureGitignore() {
const packageJson = util.readJson('package.json');
const ignore = util.readLines('.gitignore');
while (ignore[ignore.length - 1] === '') {
// remove trailing blank lines
ignore.splice(ignore.length - 1, 1);
}
const ignoreIfExists = ['node_modules', 'cdk.out', 'dist', 'lib', 'coverage', 'yarn-error.log', '.nyc_output', '.eslintcache', '.DS_Store', 'npm-debug.log', '.parcel-cache'];
for (const maybe of ignoreIfExists) {
if (fs.existsSync(maybe)) {
Expand All @@ -13,12 +18,16 @@ export default function configureGitignore() {
}
}
}
if (packageJson.devDependencies.typescript && !ignore.includes('tsconfig.tsbuildinfo')) {
ignore.push('tsconfig.tsbuildinfo');
}
const removeIfIgnored = ['yarn.lock', 'package-lock.json'];
for (const remove of removeIfIgnored) {
const index = ignore.indexOf(remove);
if (index !== -1) {
ignore.splice(index, 1);
}
}
ignore.push('');
util.writeLines('.gitignore', ignore);
}
3 changes: 2 additions & 1 deletion packages/lint/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as glob from 'glob';
import root from 'app-root-path';
import * as packageJson from './packageJson.js';
import * as gitignore from './gitignore.js';
import * as typescript from './typescript.js';
import * as eslint from './eslint.js';
import * as prettier from './prettier.js';
import * as vscode from './vscode.js';
Expand Down Expand Up @@ -30,7 +31,7 @@ export default function configure() {
dirs.push(path.join(process.cwd(), file, '..'));
});
}
const plugins = [packageJson, forceDevDependencies, jest, gitignore, eslint, prettier, vscode, editorconfig, markdown, semanticRelease, cdk];
const plugins = [packageJson, forceDevDependencies, jest, typescript, gitignore, eslint, prettier, vscode, editorconfig, markdown, semanticRelease, cdk];
// eslint-disable-next-line no-inner-declarations
function exec(plugin, step) {
if (plugin[step]) {
Expand Down
36 changes: 36 additions & 0 deletions packages/lint/config/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as util from '../util.js';
import * as fs from 'fs';

const debug = util.debug('configure-typescript');

export const name = 'typescript';

export default function configure() {
const packageJson = util.readJson('package.json');
if (packageJson.name === '@joelbot/lint') {
debug("looks like you're working on @joelbot/lint repo, doing nothing");
return;
}
if ('typescript' in packageJson.devDependencies) {
debug('typescript is a devDependency, setting up tsconfig');
fs.writeFileSync(
'tsconfig.json',
JSON.stringify(
{
extends: '@joelbot/tsconfig/tsconfig.json',
},
null,
2,
),
);
packageJson.devDependencies['@joelbot/tsconfig'] = '^1.0.0';
} else {
if (fs.exists('tsconfig.json')) {
debug('typescript is not a devDependency, removing tsconfig.json');
fs.rmSync('tsconfig.json');
} else {
debug('typescript is not a devDependency, and tsconfig.json does not exist, doing nothing');
}
}
util.writeJson('package.json', packageJson);
}
10 changes: 9 additions & 1 deletion packages/lint/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@joelbot/lint",
"version": "0.0.0",
"private": true,
"private": false,
"main": "index.js",
"description": "A personal opinionated linting tool.",
"keywords": [
Expand Down Expand Up @@ -30,5 +30,13 @@
},
"engines": {
"node": ">=18"
},
"publishConfig": {
"access": "public"
},
"release": {
"branches": [
"main"
]
}
}
47 changes: 47 additions & 0 deletions packages/release/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env node

import * as fs from 'fs';
import * as cp from 'child_process';
import root from 'app-root-path';
import Debug from 'debug';

const debug = Debug(`@joelbot/release`);

debug('running in directory', process.cwd());
debug('project root directory is', root.path);

if (!fs.existsSync('package.json')) {
debug('package.json does not exist, doing nothing');
process.exit(0);
}

const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));

if (packageJson.workspaces) {
debug('running in a workspace, looping through workspaces and re-running release');
const result = cp.spawnSync('yarn', ['workspaces', 'run', 'release'], {
stdio: 'inherit',
});
process.exit(result.status);
}

if (packageJson.publishConfig?.access !== 'public') {
debug('publishConfig.access is not public, doing nothing');
process.exit(0);
}

debug('publishConfig.access is public, running semantic-release');

if (process.cwd() !== root.path) {
debug('running in a workspace folder, using semantic-release-monorepo');
const result = cp.spawnSync('yarn', ['semantic-release', '-e', 'semantic-release-monorepo'], {
stdio: 'inherit',
});
process.exit(result.status);
} else {
debug('running semantic-release in project root');
const result = cp.spawnSync('yarn', ['semantic-release'], {
stdio: 'inherit',
});
process.exit(result.status);
}
17 changes: 17 additions & 0 deletions packages/release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@joelbot/release",
"version": "0.0.0",
"private": true,
"main": "index.js",
"description": "An opinionated semantic-release wrapper / helper tool for my personal projects.",
"author": "Joel Cox <[email protected]>",
"license": "0BSD",
"type": "module",
"dependencies": {
"app-root-path": "^3.1.0",
"debug": "^4.3.4"
},
"bin": {
"release": "index.js"
}
}
5 changes: 4 additions & 1 deletion packages/test-react-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"description": "a simple package with react to test the lint config with",
"type": "module",
"dependencies": {
"react": "^18.2.0"
"immer": "^10.0.4",
"react": "^18.2.0",
"use-immer": "^0.9.0"
},
"devDependencies": {
"@types/react": "^18.2.78",
"typescript": "^5.4.2"
}
}
37 changes: 28 additions & 9 deletions packages/test-react-typescript/test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import React from 'react';
import { useImmer } from 'use-immer';

interface State {
value: string;
count: number;
}

export function Test() {
const [value, setValue] = React.useState('');
const [count, setCount] = React.useState(0);
React.useEffect(() => {
// linter should enforce `value` in hook dependencies
console.log(value);
}, [value]);
const [state, update] = useImmer<State>({
value: '',
count: 0,
});
return (
<div>
<input onChange={(e) => setValue(e.target.value)} type="text" value={value} />
<button onClick={() => setCount(count + 1)} type="button">
type attribute should be required {count}
<input
onChange={(e) =>
update((draft) => {
draft.value = e.target.value;
})
}
type="text"
value={state.value}
/>
<button
onClick={() => {
update((draft) => {
draft.count++;
});
}}
type="button"
>
type attribute should be required {state.count}
</button>
</div>
);
Expand Down
20 changes: 20 additions & 0 deletions packages/tsconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@joelbot/tsconfig",
"version": "0.0.0",
"private": false,
"description": "just a base tsconfig",
"author": "Joel Cox <[email protected]>",
"license": "0BSD",
"repository": {
"type": "git",
"url": "https://github.com/joelcox22/lint.git"
},
"publishConfig": {
"access": "public"
},
"release": {
"branches": [
"main"
]
}
}
30 changes: 30 additions & 0 deletions packages/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compilerOptions": {
"incremental": true,
"target": "ESNext",
"jsx": "react",
"moduleDetection": "auto",
"moduleResolution": "NodeNext",
"module": "Node16",
"allowArbitraryExtensions": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./",
"removeComments": true,
"importsNotUsedAsValues": "remove",
"downlevelIteration": true,
"emitBOM": true,
"newLine": "lf",
"stripInternal": true,
"noEmitOnError": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"allowImportingTsExtensions": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["node_modules", "cdk.out", "dist", "build", "coverage", "public", ".parcel-cache", ".wrangler"]
}
1 change: 1 addition & 0 deletions tsconfig.json
Loading

0 comments on commit 419a0d8

Please sign in to comment.