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

Migrate linting and tests away from tsdx #29

Merged
merged 8 commits into from
Nov 6, 2021
Merged
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
25 changes: 22 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
/* eslint-env node */

module.exports = {
root: true,
extends: ['eslint:recommended', 'prettier/@typescript-eslint', 'prettier'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'prettier'],

parserOptions: {
ecmaVersion: 2020,
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'error',
},

overrides: [
{
files: ['**/*.test.*', '**/tests/*.*'],
env: {
jest: true,
},
},
{
// Only add typescript rules for typescript files
files: ['**/*.ts', '**/*.tsx'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
},
],

ignorePatterns: [
'build/',
'dist/',
'coverage/',
'coverage-local/',
'dist/',
'legacy-types/',
'lib-dist/',
'node_modules/',
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 12.x, 14.x, 15.x, 16.x ]
node-version: [ 12.x, 14.x, 16.x, 17.x ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.2.0
16.13.0
2 changes: 1 addition & 1 deletion examples/example-library/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const exampleLibraryFn = () => {
const exampleLibraryFn = (): void => {
console.log('exampleLibraryFn!');
};

Expand Down
9 changes: 7 additions & 2 deletions jest-base.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/* eslint-env node */

module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
collectCoverage: true,
coverageReporters: ['json', 'html', 'lcov'],

testPathIgnorePatterns: ['/build/', '/dist/', '/lib-dist/', '/node_modules/'],
coveragePathIgnorePatterns: ['.*\\.(ignored|stories|test)\\.*'],
// coverageDirectory should be set by consumer
// collectCoverageFrom should be set by consumer

// This base config is incomplete: the consumer should set `roots`, `coverageDirectory`, and `collectCoverageFrom`
};
37 changes: 20 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"url": "http://stevenpautz.com/"
},
"engines": {
"node": "^12 || >=14",
"node": "^12 || ^14 || ^15 || ^16 || ^17",
"yarn": "1.*"
},
"scripts": {
Expand All @@ -42,42 +42,45 @@
"bootstrap": "lerna bootstrap",
"format": "prettier --write .",
"format:verify": "prettier --list-different .",
"lint": "tsdx lint . --max-warnings 0",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix --max-warnings 0",
"lint-staged": "lint-staged",
"packagelint": "packagelint",
"release:version": "yarn lerna version --no-changelog --no-push --no-git-tag-version ",
"release:tag": "cross-env HUSKY_BYPASS=true yarn lerna version --no-changelog --no-push --sign-git-commit --amend ",
"release:postpublish": "standard-version --commit-all --sign --skip.changelog --release-as ",
"test": "yon run test:coverage",
"test:clean": "rimraf ./coverage",
"test:coverage": "yon run test:clean && tsdx test --coverage",
"test:nowatch": "yon run test:clean && tsdx test",
"test:watch": "yon run test:clean && tsdx test --watch",
"test:watchcoverage": "yon run test:clean && tsdx test --watchAll --coverage",
"test:coverage": "yon run test:clean && jest --coverage",
"test:nowatch": "yon run test:clean && jest --coverage=false --bail",
"test:watch": "yon run test:clean && jest --coverage=false --watch",
"test:watchcoverage": "yon run test:clean && jest --coverage --watchAll",
"types": "tsc --noEmit --p tsconfig.json"
},
"dependencies": {},
"devDependencies": {
"@tsconfig/recommended": "1.0.1",
"@types/node": "16.4.0",
"@types/node": "16.11.6",
"@typescript-eslint/eslint-plugin": "5.3.0",
"@typescript-eslint/parser": "5.3.0",
"cross-env": "7.0.3",
"downlevel-dts": "0.7.0",
"eslint-plugin-prettier": "3.4.0",
"eslint": "8.2.0",
"eslint-config-prettier": "8.3.0",
"gh-pages": "3.2.3",
"husky": "7.0.1",
"husky": "7.0.4",
"jest": "27.3.1",
"lerna": "4.0.0",
"lint-staged": "11.0.1",
"prettier": "2.3.2",
"lint-staged": "11.2.6",
"prettier": "2.4.1",
"rimraf": "3.0.2",
"standard-version": "9.3.1",
"standard-version": "9.3.2",
"ts-jest": "27.0.7",
"tsdx": "0.14.1",
"typescript": "4.3.5",
"tslib": "2.3.1",
"typescript": "4.4.4",
"yarn-or-npm": "3.0.1"
},
"resolutions": {
"**/@typescript-eslint/eslint-plugin": "^4.28.4",
"**/@typescript-eslint/parser": "^4.28.4"
},
"lint-staged": {
"**/*.{css,html,js,jsx,json,less,md,scss,ts,tsx}": [
"prettier --write"
Expand Down
11 changes: 6 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@
"build:watch": "tsdx watch",
"format": "prettier --write .",
"format:verify": "prettier --list-different .",
"lint": "tsdx lint . --max-warnings 0",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix --max-warnings 0",
"release:changelog": "standard-version --skip.commit --skip.tag --release-as ",
"test": "yon run test:coverage",
"test:clean": "rimraf ./coverage-local",
"test:coverage": "yon run test:clean && tsdx test --coverage --passWithNoTests",
"test:nowatch": "yon run test:clean && tsdx test",
"test:watch": "yon run test:clean && tsdx test --watch",
"test:watchcoverage": "yon run test:clean && tsdx test --watchAll --coverage",
"test:coverage": "yon run test:clean && jest --coverage",
"test:nowatch": "yon run test:clean && jest --coverage=false --bail",
"test:watch": "yon run test:clean && jest --coverage=false --watch",
"test:watchcoverage": "yon run test:clean && jest --coverage --watchAll",
"types": "tsc --p tsconfig.json --noEmit"
},
"dependencies": {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/__tests__/todo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('@TODO', () => {
it('@TODO', () => {
expect('@TODO').toEqual('@TODO');
});
});
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
nvmrcRuleDefinition,
} from './rules';

const packagelintReporters: Record<string, PackagelintReporterConstructor<any>> = {
const packagelintReporters: Record<string, PackagelintReporterConstructor> = {
internalDebugReporter: InternalDebugReporter,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const packagelintRules: Record<string, PackagelintRuleDefinition<any>> = {
'always-fail': alwaysFailRuleDefinition,
'always-pass': alwaysPassRuleDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class InternalDebugReporter implements PackagelintReporterInstance {
this._logEvent('getLastError', ...args);
}

_logEvent(eventName: PackagelintReporterEventName, ...args: Array<any>): void {
_logEvent(eventName: PackagelintReporterEventName, ...args: Array<unknown>): void {
if (this._eventsToLog[eventName]) {
this._callback(`${this._prefix}: ${eventName}`, ...args);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/rules/always-fail/always-fail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { PackagelintRuleDefinition, PackagelintValidationContext } from '@packagelint/types';
import {
PackagelintRuleDefinition,
PackagelintValidationContext,
PackagelintValidationFnReturn,
} from '@packagelint/types';

export type AlwaysFailRuleOptions = {};
export type AlwaysFailRuleOptions = Record<never, never>;

const alwaysFailRuleDefinition: PackagelintRuleDefinition<AlwaysFailRuleOptions> = {
name: 'always-fail',
Expand All @@ -19,7 +23,7 @@ const alwaysFailRuleDefinition: PackagelintRuleDefinition<AlwaysFailRuleOptions>
function alwaysFailRuleValidationFn(
_options: AlwaysFailRuleOptions,
packageContext: PackagelintValidationContext,
) {
): PackagelintValidationFnReturn {
return packageContext.createErrorToReturn('alwaysFail');
}

Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/rules/always-pass/always-pass.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PackagelintRuleDefinition, PackagelintValidationContext } from '@packagelint/types';
import { PackagelintRuleDefinition } from '@packagelint/types';

export type AlwaysPassRuleOptions = {};
export type AlwaysPassRuleOptions = Record<never, never>;

const alwaysPassRuleDefinition: PackagelintRuleDefinition<AlwaysPassRuleOptions> = {
name: 'always-pass',
Expand All @@ -16,10 +16,7 @@ const alwaysPassRuleDefinition: PackagelintRuleDefinition<AlwaysPassRuleOptions>
doValidation: alwaysPassRuleValidationFn,
};

function alwaysPassRuleValidationFn(
_options: AlwaysPassRuleOptions,
_packageContext: PackagelintValidationContext,
) {
function alwaysPassRuleValidationFn(/* _options: AlwaysPassRuleOptions, _packageContext: PackagelintValidationContext */): null {
return null;
}

Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/rules/always-throw/always-throw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PackagelintRuleDefinition, PackagelintValidationContext } from '@packagelint/types';
import { PackagelintRuleDefinition } from '@packagelint/types';

export type AlwaysThrowRuleOptions = {};
export type AlwaysThrowRuleOptions = Record<never, never>;

const alwaysThrowRuleDefinition: PackagelintRuleDefinition<AlwaysThrowRuleOptions> = {
name: 'always-throw',
Expand All @@ -14,10 +14,7 @@ const alwaysThrowRuleDefinition: PackagelintRuleDefinition<AlwaysThrowRuleOption
doValidation: alwaysThrowRuleValidationFn,
};

function alwaysThrowRuleValidationFn(
_options: AlwaysThrowRuleOptions,
_packageContext: PackagelintValidationContext,
): null {
function alwaysThrowRuleValidationFn(/* _options: AlwaysThrowRuleOptions, _packageContext: PackagelintValidationContext, */): null {
throw new Error('This rule will always throw an error');
}

Expand Down
48 changes: 24 additions & 24 deletions packages/core/src/rules/nvmrc/nvmrc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import semver from 'semver';

import { PackagelintRuleDefinition, PackagelintValidationContext } from '@packagelint/types';
import { PackagelintRuleDefinition, PackagelintValidationFn } from '@packagelint/types';

const { readFile } = fs.promises;

Expand All @@ -10,28 +10,10 @@ export type NvmrcRuleOptions = {
version: string;
};

const nvmrcRuleDefinition: PackagelintRuleDefinition<NvmrcRuleOptions> = {
name: 'nvmrc',
docs: {
description: 'Require a .nvmrc file, maybe with a specific version range',
url: 'https://github.com/spautz/packagelint',
},
defaultOptions: {
fileName: '.nvmrc',
version: '>=10',
},
messages: {
fileNotFound: '{{fileName}} not found',
invalidNvmrc: 'Invalid {{fileName}}: must contain a version number',
invalidVersion: 'Invalid Node version in {{fileName}}: must match "{{version}}"',
},
doValidation: nvmrcRuleValidation,
};

async function nvmrcRuleValidation(
options: NvmrcRuleOptions,
packageContext: PackagelintValidationContext,
) {
const nvmrcRuleValidation: PackagelintValidationFn<NvmrcRuleOptions> = async (
options,
packageContext,
) => {
const { fileName, version } = options;
const { findFileUp, createErrorToReturn, setErrorData } = packageContext;

Expand All @@ -52,6 +34,24 @@ async function nvmrcRuleValidation(
}

return null;
}
};

const nvmrcRuleDefinition: PackagelintRuleDefinition<NvmrcRuleOptions> = {
name: 'nvmrc',
docs: {
description: 'Require a .nvmrc file, maybe with a specific version range',
url: 'https://github.com/spautz/packagelint',
},
defaultOptions: {
fileName: '.nvmrc',
version: '>=10',
},
messages: {
fileNotFound: '{{fileName}} not found',
invalidNvmrc: 'Invalid {{fileName}}: must contain a version number',
invalidVersion: 'Invalid Node version in {{fileName}}: must match "{{version}}"',
},
doValidation: nvmrcRuleValidation,
};

export { nvmrcRuleDefinition, nvmrcRuleValidation };
5 changes: 3 additions & 2 deletions packages/packagelint-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"*.md"
],
"engines": {
"node": "^12 || >=14"
"node": "^12 || ^14 || ^15 || ^16 || ^17"
},
"preferGlobal": true,
"bin": {
Expand All @@ -44,7 +44,8 @@
"____ INDIVIDUAL COMMANDS ___________________________________________": "",
"format": "prettier --write .",
"format:verify": "prettier --list-different .",
"lint": "tsdx lint . --max-warnings 0",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix --max-warnings 0",
"release:changelog": "standard-version --skip.commit --skip.tag --release-as "
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/packagelint/bin/packagelint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const onFatalError = (...args) => {

const { packagelintCli } = require('../lib-dist/cli');
try {
const [exitCode, validationOutput] = await packagelintCli(process.argv);
const [exitCode, validationOutput, error] = await packagelintCli(process.argv);

console.log('packagelintCli() ', exitCode, validationOutput);
console.log('packagelintCli() ', exitCode, validationOutput, error);

process.exitCode = exitCode;
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions packages/packagelint/lib-src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import findUp from 'find-up';
import { PackagelintUserConfig } from '@packagelint/types';
import { PackagelintOutput, PackagelintUserConfig } from '@packagelint/types';

import { prepareConfig } from './prepare';
import { validatePreparedConfig } from './validate';
Expand All @@ -13,13 +13,13 @@ export * from './exitCodes';
export * from './util';

async function findPackagelintConfigFile(
configFileName: string = '.packagelint.js',
configFileName = '.packagelint.js',
pathToSearchFrom: string = process.cwd(),
): Promise<string | undefined> {
return findUp(configFileName, { cwd: pathToSearchFrom });
}

async function runPackagelint(userConfig: PackagelintUserConfig) {
async function runPackagelint(userConfig: PackagelintUserConfig): Promise<PackagelintOutput> {
const preparedConfig = await prepareConfig(userConfig);
const validationOutput = await validatePreparedConfig(preparedConfig);
return validationOutput;
Expand Down
Loading