Skip to content

Commit

Permalink
chore: setup ci and typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 21, 2023
1 parent 51b27f6 commit adaed68
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 16 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,87 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Lint
run: nr lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Typecheck
run: nr typecheck

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: [16.x, 18.x]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Build
run: nr build

- name: Test
run: nr test
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -8,6 +8,7 @@
"license": "MIT",
"scripts": {
"lint": "pnpm -r run stub && eslint .",
"typecheck": "tsc --noEmit",
"test": "pnpm -r run test",
"build": "pnpm -r run build",
"release": "bumpp -r && pnpm -r publish"
Expand Down
9 changes: 4 additions & 5 deletions packages/eslint-config/src/configs/jsonc.ts
@@ -1,19 +1,18 @@
import jsoncPlugin, { configs } from 'eslint-plugin-jsonc'
import jsoncParser from 'jsonc-eslint-parser'
import type { FlatESLintConfigItem } from 'eslint-define-config'
import { GLOB_JSON, GLOB_JSON5, GLOB_JSONC } from '../globs'
import { parserJsonc, pluginJsonc } from '../plugins'

export const jsonc: FlatESLintConfigItem[] = [
{
files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
languageOptions: {
parser: jsoncParser,
parser: parserJsonc,
},
plugins: {
jsonc: jsoncPlugin,
jsonc: pluginJsonc as any,
},
rules: {
...configs['recommended-with-jsonc'].rules as any,
...pluginJsonc.configs['recommended-with-jsonc'].rules as any,
'jsonc/array-bracket-spacing': ['error', 'never'],
'jsonc/comma-dangle': ['error', 'never'],
'jsonc/comma-style': ['error', 'last'],
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-config/src/configs/stylistic.ts
Expand Up @@ -115,24 +115,24 @@ export const typescriptStylistic: FlatESLintConfigItem[] = [
]

// TODO: move to ESLint Stylistic
function stylisticJsToTS(rules: Record<string, any>) {
function stylisticJsToTS(input: Record<string, any>) {
return {
// turn off all stylistic rules from @stylistic/js
...Object.fromEntries(
Object.entries(rules)
.map(([key]) => rules.find(i => i.name === key) ? [key, OFF] : null)
Object.entries(input)
.map(([key]) => rules.find(i => i.name === key) ? [key, OFF] : null!)
.filter(Boolean),
),
// rename all stylistic rules from @stylistic/js to @stylistic/ts
...Object.fromEntries(
Object.entries(rules)
Object.entries(input)
.map(([key, value]) => {
const newKey = key.replace('@stylistic/js', '@stylistic/ts')
if (newKey === key)
return null
return null!
return rules.find(i => i.name === newKey)
? [key.replace('@stylistic/js', '@stylistic/ts'), value]
: null
: null!
})
.filter(Boolean),
),
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-config/src/configs/typescript.ts
Expand Up @@ -19,12 +19,12 @@ export const typescript: FlatESLintConfigItem[] = [
},
},
plugins: {
'@typescript-eslint': pluginTs,
'@typescript-eslint': pluginTs as any,
'antfu': pluginAntfu,
'import': pluginImport,
},
rules: {
...pluginTs.configs['eslint-recommended'].overrides[0].rules,
...pluginTs.configs['eslint-recommended'].overrides![0].rules,
...pluginTs.configs.strict.rules,

// TS
Expand Down Expand Up @@ -114,7 +114,7 @@ export function typescriptWithLanguageServer({
},
},
plugins: {
'@typescript-eslint': pluginTs,
'@typescript-eslint': pluginTs as any,
},
rules: {
'@typescript-eslint/await-thenable': 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/configs/unicorn.ts
@@ -1,5 +1,5 @@
import type { FlatESLintConfigItem } from 'eslint-define-config'
import pluginUnicorn from 'eslint-plugin-unicorn'
import { pluginUnicorn } from '../plugins'

export const unicorn: FlatESLintConfigItem[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/configs/yml.ts
Expand Up @@ -10,7 +10,7 @@ export const yml: FlatESLintConfigItem[] = [
parser: parserYml,
},
plugins: {
yml: pluginYml,
yml: pluginYml as any,
},
rules: {
...pluginYml.configs.standard.rules as any,
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-config/src/plugins.ts
Expand Up @@ -6,6 +6,7 @@ export { default as pluginComments } from 'eslint-plugin-eslint-comments'
export { default as pluginImport } from 'eslint-plugin-i'
// @ts-expect-error missing types
export { default as pluginJsdoc } from 'eslint-plugin-jsdoc'
export { default as pluginJsonc } from 'eslint-plugin-jsonc'
// @ts-expect-error missing types
export { default as pluginMarkdown } from 'eslint-plugin-markdown'
// @ts-expect-error missing types
Expand All @@ -28,3 +29,4 @@ export { default as pluginNoOnlyTests } from 'eslint-plugin-no-only-tests'
export { default as parserTs } from '@typescript-eslint/parser'
export { default as parserVue } from 'vue-eslint-parser'
export { default as parserYml } from 'yaml-eslint-parser'
export { default as parserJsonc } from 'jsonc-eslint-parser'
2 changes: 2 additions & 0 deletions packages/eslint-plugin-antfu/src/rules/no-cjs-exports.ts
Expand Up @@ -19,6 +19,8 @@ export default createEslintRule<Options, MessageIds>({
defaultOptions: [],
create: (context) => {
const extension = context.getFilename().split('.').pop()
if (!extension)
return {}
if (!['ts', 'tsx', 'mts', 'cts'].includes(extension))
return {}

Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-antfu/src/rules/no-ts-export-equal.ts
Expand Up @@ -20,6 +20,8 @@ export default createEslintRule<Options, MessageIds>({
defaultOptions: [],
create: (context) => {
const extension = context.getFilename().split('.').pop()
if (!extension)
return {}
if (!['ts', 'tsx', 'mts', 'cts'].includes(extension))
return {}

Expand Down
Expand Up @@ -49,8 +49,12 @@ export default createEslintRule<Options, MessageIds>({

function * removeTypeSpecifier(fixer: RuleFixer, sourceCode: Readonly<SourceCode>, node: TSESTree.ImportDeclaration) {
const importKeyword = sourceCode.getFirstToken(node)
if (!importKeyword)
return

const typeIdentifier = sourceCode.getTokenAfter(importKeyword)
if (!typeIdentifier)
return

yield fixer.remove(typeIdentifier)

Expand Down

0 comments on commit adaed68

Please sign in to comment.