Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint action #24

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"extends": [
"./lib/all-legacy"
],
"rules": {
// "semi": [1, "always"]
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
// "semi": [1, "always"]
}
}
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: yarn install --immutable
run: yarn install --frozen-lockfile --ignore-scripts --no-progress --prefer-offline

- name: Run Tests
run: yarn test --coverage

- name: Run Build
- name: Build Lint Pilot
run: yarn build

- name: Lint
- name: Run Lint Pilot
run: |
yarn lint --ignore-patterns '**/*.ts'
yarn lint --eslint-use-legacy-config --ignore-patterns '**/*.ts'
Expand Down
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default [
{
rules: {
// semi: [1, 'always'],
}
}
},
},
]
5 changes: 0 additions & 5 deletions jest-config/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
* MOCKS AND SPIES
*/

jest.mock('log-symbols', () => ({
warning: '!',
error: 'X',
}))

jest.spyOn(process, 'exit').mockImplementation(code => {
throw new Error(`process.exit(${code})`)
})
Expand Down
5 changes: 1 addition & 4 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const config: JestConfigWithTsJest = {
clearMocks: true,
collectCoverageFrom: [
'src/**/*',
// TODO: Write tests for these files when they are less likely to change
'!src/index.ts',
'!src/linters/index.ts',
],
coverageDirectory: 'coverage',
coverageThreshold: {
Expand Down Expand Up @@ -36,7 +33,7 @@ const config: JestConfigWithTsJest = {
},
transformIgnorePatterns: [
'./node_modules/(?!(chalk)/)',
]
],
}

export default config
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lint-pilot",
"description": "Lint Pilot: Your co-pilot for maintaining high code quality with seamless ESLint, Stylelint, and MarkdownLint integration.",
"description": "Lint Pilot: Your co-pilot for maintaining high code quality with seamless ESLint, Stylelint, and Markdownlint integration.",
"repository": {
"type": "git",
"url": "git+https://github.com/01taylop/lint-pilot.git"
Expand Down Expand Up @@ -33,7 +33,6 @@
"eslint-plugin-sort-destructure-keys": "2.0.0",
"eslint-plugin-sort-exports": "0.9.1",
"glob": "10.4.5",
"log-symbols": "7.0.0",
"markdownlint": "0.35.0",
"markdownlint-rule-helpers": "0.26.0",
"node-notifier": "10.0.1",
Expand All @@ -50,6 +49,7 @@
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.4",
"@babel/preset-typescript": "7.24.7",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "11.1.6",
"@types/eslint": "9.6.1",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'

import json from '@rollup/plugin-json'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import copy from 'rollup-plugin-copy'
Expand Down Expand Up @@ -37,6 +38,7 @@ export default [{
format: 'es',
},
plugins: [
json(),
nodeResolve({
preferBuiltins: true,
}),
Expand Down
119 changes: 119 additions & 0 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import chalk from 'chalk'

import { description, name, version } from '../../package.json'
import { lint } from '../commands'
import createProgram from '../index'

import type { LintOptions } from '@Types/commands'

jest.mock('chalk', () => ({
red: jest.fn(text => text),
}))

jest.mock('../commands', () => ({
lint: jest.fn(),
}))

describe('lint-pilot', () => {

it('displays the help text', () => {
const program = createProgram()
const helpInformation = program
.configureHelp({
helpWidth: -1,
})
.helpInformation()

expect(helpInformation).toStrictEqual(`Usage: ${name} [options] [command]

${description}

Options:
-V, --version output the version number
-h, --help display help for command

Commands:
lint [options] run all linters: ESLint, Stylelint, and Markdownlint (default)
help [command] display help for command
`)
})

it('displays the version', () => {
const program = createProgram()
program
.configureOutput({ writeOut: jest.fn() })
.exitOverride()

expect(() => {
program.parse(['node', './index.ts', '--version'])
}).toThrow(version)
})

it('handles unknown options', () => {
expect.assertions(4)

const writeErrMock = jest.fn()

const program = createProgram()
program
.configureOutput({
writeErr: writeErrMock,
})

try {
program.parse(['node', './index.ts', '--unknown'])
} catch (e: any) {
expect(e.message).toMatch('process.exit(1)')
}

expect(chalk.red).toHaveBeenCalledOnceWith(expect.stringContaining('✗ unknown option \'--unknown\''))
expect(writeErrMock).toHaveBeenNthCalledWith(1, expect.stringContaining('✗ unknown option \'--unknown\''))
expect(writeErrMock).toHaveBeenNthCalledWith(2, expect.stringContaining('💡 Run `lint-pilot --help` for more information.'))
})

it('calls the lint command by default', () => {
const program = createProgram()
program.parse(['node', './index.ts'])

expect(lint).toHaveBeenCalledTimes(1)
})

it('calls the lint command with default options', () => {
const program = createProgram()
program.parse(['node', './index.ts', 'lint'])

const expectedOptions: LintOptions = {
cache: false,
clearCache: false,
debug: false,
emoji: '✈️',
eslintUseLegacyConfig: false,
fix: false,
title: 'Lint Pilot',
watch: false,
}

expect(lint).toHaveBeenCalledOnceWith(expectedOptions)
})

it('calls the lint command with configured options', () => {
const program = createProgram()
program.parse(['node', './index.ts', 'lint', '--emoji', '🚀', '--title', 'Rocket Lint', '--fix', '--watch', '--cache', '--clearCache', '--ignore-dirs', 'node_modules', '--ignore-patterns', 'dist', '--eslint-include', '*.mdx', '--debug', '--eslint-use-legacy-config'])

const expectedOptions: LintOptions = {
cache: true,
clearCache: true,
debug: true,
emoji: '🚀',
eslintInclude: ['*.mdx'],
eslintUseLegacyConfig: true,
fix: true,
ignoreDirs: ['node_modules'],
ignorePatterns: ['dist'],
title: 'Rocket Lint',
watch: true,
}

expect(lint).toHaveBeenCalledOnceWith(expectedOptions)
})
})
5 changes: 5 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import lint from './lint'

export {
lint,
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import colourLog from '@Utils/colourLog'
import { Linter } from '@Types'
import { Linter } from '@Types/lint'
import colourLog from '@Utils/colour-log'

import getFilePatterns from '../filePatterns'
import { getFilePatterns } from '../file-patterns'

describe('filePatterns', () => {
describe('getFilePatterns', () => {

jest.spyOn(colourLog, 'config').mockImplementation(() => {})
jest.spyOn(console, 'log').mockImplementation(() => {})
beforeEach(() => {
jest.spyOn(colourLog, 'config').mockImplementation(() => true)
jest.spyOn(console, 'log').mockImplementation(() => true)
})

it('returns the correct file patterns for eslint', () => {
it('returns the default file patterns for ESLint', () => {
const filePatterns = getFilePatterns({})

const expectedPatterns = [
Expand All @@ -19,7 +21,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('ESLint Patterns', expectedPatterns)
})

it('returns the correct file patterns for eslint with an additional include pattern', () => {
it('returns the file patterns for ESLint with an additional include pattern', () => {
const filePatterns = getFilePatterns({
eslintInclude: 'foo'
})
Expand All @@ -33,7 +35,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('ESLint Patterns', expectedPatterns)
})

it('returns the correct file patterns for eslint with several additional include patterns', () => {
it('returns the file patterns for ESLint with several additional include patterns', () => {
const filePatterns = getFilePatterns({
eslintInclude: ['foo', 'bar'],
})
Expand All @@ -48,7 +50,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('ESLint Patterns', expectedPatterns)
})

it('returns the correct file patterns for markdownlint', () => {
it('returns the default file patterns for Markdownlint', () => {
const filePatterns = getFilePatterns({})

const expectedPatterns = [
Expand All @@ -59,7 +61,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('Markdownlint Patterns', expectedPatterns)
})

it('returns the correct file patterns for stylelint', () => {
it('returns the default file patterns for Stylelint', () => {
const filePatterns = getFilePatterns({})

const expectedPatterns = [
Expand All @@ -70,7 +72,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('Stylelint Patterns', expectedPatterns)
})

it('returns the correct ignore file patterns', () => {
it('returns the default ignore file patterns', () => {
const filePatterns = getFilePatterns({})

const expectedPatterns = [
Expand All @@ -82,7 +84,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('Ignore', expectedPatterns)
})

it('returns the correct ignore file patterns with an additional directory ignored', () => {
it('returns the ignore file patterns with an additional directory ignored', () => {
const filePatterns = getFilePatterns({
ignoreDirs: 'foo'
})
Expand All @@ -96,7 +98,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('Ignore', expectedPatterns)
})

it('returns the correct ignore file patterns with several additional directories ignored', () => {
it('returns the ignore file patterns with several additional directories ignored', () => {
const filePatterns = getFilePatterns({
ignoreDirs: ['foo', 'bar'],
})
Expand All @@ -110,7 +112,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('Ignore', expectedPatterns)
})

it('returns the correct ignore file patterns with an additional pattern ignored', () => {
it('returns the ignore file patterns with an additional pattern ignored', () => {
const filePatterns = getFilePatterns({
ignorePatterns: 'foo'
})
Expand All @@ -125,7 +127,7 @@ describe('filePatterns', () => {
expect(colourLog.config).toHaveBeenCalledWith('Ignore', expectedPatterns)
})

it('returns the correct ignore file patterns with several additional patterns ignored', () => {
it('returns the ignore file patterns with several additional patterns ignored', () => {
const filePatterns = getFilePatterns({
ignorePatterns: ['foo', 'bar'],
})
Expand Down
Loading
Loading