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

Bring project back to life #26

Merged
merged 28 commits into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b636f6f
Define engines
Shinigami92 Jul 24, 2020
581289d
Add yarn.lock
Shinigami92 Jul 24, 2020
f9592a3
Update license year
Shinigami92 Jul 24, 2020
499e912
Prefer minor only updates
Shinigami92 Jul 24, 2020
f51ec9a
Prefer suggested casing
Shinigami92 Jul 24, 2020
ae66f0a
Update prettier
Shinigami92 Jul 24, 2020
161b8c3
Ignore some folders
Shinigami92 Jul 24, 2020
fc0aa8d
Execute prettier
Shinigami92 Jul 24, 2020
7c2bbb9
Prefer .prettierrc.json
Shinigami92 Jul 24, 2020
5d63386
Remove tslint
Shinigami92 Jul 24, 2020
b3f44f4
Prepare linter script
Shinigami92 Jul 24, 2020
28cd4ba
Update dependencies
Shinigami92 Jul 24, 2020
3d73390
Fix build errors
Shinigami92 Jul 24, 2020
62aeaaa
Remove babel bridge
Shinigami92 Jul 24, 2020
e439c47
Replace npm-check with yarn outdated
Shinigami92 Jul 24, 2020
781a34c
Add types
Shinigami92 Jul 24, 2020
ac176d8
__mocks__ can be formatted
Shinigami92 Jul 24, 2020
2f5ee31
Update jest config
Shinigami92 Jul 24, 2020
d72e0c8
Add typedefs
Shinigami92 Jul 24, 2020
b931f91
Organize imports
Shinigami92 Jul 24, 2020
9964bf5
Add types for loglevel-colored-level-prefix
Shinigami92 Jul 24, 2020
951d22c
Enable --frozen-lockfile in ci
Shinigami92 Jul 24, 2020
ad55f4e
Remove codeclimate dependency
Shinigami92 Jul 24, 2020
2a0f0db
Update badges
Shinigami92 Jul 25, 2020
cdd4f12
Use minor update strategy for dependencies
Shinigami92 Jul 25, 2020
6eff286
Allow wider range of node lts engine
Shinigami92 Jul 25, 2020
eedffa3
Improve typedef
Shinigami92 Jul 25, 2020
01d33e1
Order imports
Shinigami92 Jul 25, 2020
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
8 changes: 0 additions & 8 deletions .codeclimate.yml

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
run: yarn versions

- name: Install dependencies
run: yarn install #--frozen-lockfile
run: yarn install --frozen-lockfile

# - name: Check
# run: yarn check
- name: Check outdated dependencies
run: yarn outdated

# - name: Lint
# run: yarn lint
- name: Lint
run: yarn lint

- name: Audit dependencies
run: yarn audit --groups dependencies
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.log
coverage/
dist/
node_modules/
package-lock.json
yarn.lock
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
coverage/
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Simon Fridlund
Copyright (c) 2017-2020 Simon Fridlund

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# @linter/core

[![Build status](https://travis-ci.org/linterjs/core.svg?branch=master)](https://travis-ci.org/linterjs/core)
[![Build status](https://ci.appveyor.com/api/projects/status/wk2n9yn57qf594e1?svg=true)](https://ci.appveyor.com/project/linterjs/core)
[![codecov](https://codecov.io/gh/linterjs/core/branch/master/graph/badge.svg)](https://codecov.io/gh/linterjs/core)
[![Maintainability](https://api.codeclimate.com/v1/badges/747c6f23ee4dfa61f522/maintainability)](https://codeclimate.com/github/linterjs/core/maintainability)
<!-- [![codecov](https://codecov.io/gh/linterjs/core/branch/master/graph/badge.svg)](https://codecov.io/gh/linterjs/core) -->
<!-- [![Maintainability](https://api.codeclimate.com/v1/badges/747c6f23ee4dfa61f522/maintainability)](https://codeclimate.com/github/linterjs/core/maintainability) -->

[![NPM package](https://img.shields.io/npm/v/@linter/core.svg?style=flat-square)](https://www.npmjs.com/package/@linter/core)
[![NPM downloads](https://img.shields.io/npm/dt/@linter/core.svg?style=flat-square)](https://www.npmjs.com/package/@linter/core)
[![Build Status](https://github.com/linterjs/core/workflows/CI/badge.svg?branch=master)](https://github.com/linterjs/core/actions?query=branch%3Amaster+workflow%3ACI)
[![Known vulnerabilities](https://snyk.io/test/github/linterjs/core/badge.svg)](https://snyk.io/test/github/linterjs/core)
[![code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io)
[![license: MIT](https://img.shields.io/github/license/linterjs/core.svg?style=flat-square)](https://github.com/linterjs/core/blob/master/LICENSE.md)
[![Discord chat](https://img.shields.io/badge/chat-on%20discord-7289da.svg)](https://discord.gg/cNUqYNq)
[![Spectrum chat](https://raw.githubusercontent.com/withspectrum/badge/5da682a8369e3b03b50acea6dee23d18ee29a12f/badge_small.svg)](https://spectrum.chat/linterjs?tab=posts)

This is the core component of `@linter`. This is used by the cli,
editor integrations and linter providers.
This is the core component of `@linter`. This is used by the cli, editor integrations and linter providers.
10 changes: 5 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module.exports = {
collectCoverage: true,
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this change was to fix non passing tests, let's try and fix the tests later so we get 100 coverage as the only thing I actually want to test is this package's API and all permutations of using the API. I don't want to have tests of implementation details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not my aim to fix test passing but 100% coverage is something that sometimes cannot be possible at all
A coverage of 85%-95% is totally valid

Lines like https://github.com/linterjs/core/blob/master/src/errors.ts#L4-L7 wont be covered (currently) 🤔

branches: 85,
functions: 85,
lines: 85,
statements: -10,
},
},
globals: {
"ts-jest": {
useBabelrc: true,
babelConfig: true,
},
},
moduleFileExtensions: ["js", "jsx", "json", "ts", "tsx"],
Expand Down
49 changes: 23 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,33 @@
"dependencies": {
"common-tags": "^1.8.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ~ will only allow PATCH version updates, while ^ will allow MINOR version updates. I guess I'm ok with only allowing PATCH updates, however if this package will be using @linter/cli in the future that will have to be using ^ as our packages will never have changes to PATCH as that will always be 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry! you are right, but only for dependencies.
But we should use ~ for devDependencies

I'm always using ~ but I'm using them in frontend projects, and these are not dependencies for other projects ^^

"loglevel-colored-level-prefix": "^1.0.0",
"read-pkg-up": "^4.0.0",
"read-pkg-up": "^7.0.1",
"require-relative": "^0.8.7",
"tslib": "^1.9.3"
"tslib": "^2.0.0"
},
"description": "Lint all the things... with one command",
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@types/jest": "^23.3.2",
"@types/node": "^10.9.4",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"codeclimate-test-reporter": "^0.5.0",
"codecov": "^3.1.0",
"jest": "^23.5.0",
"jest-cli": "^23.5.0",
"jest-plugin-fs": "^2.9.0",
"jest-plugins": "^2.9.0",
"npm-check": "^5.8.0",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"ts-jest": "^23.1.4",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-language-service": "^0.9.9",
"tslint-plugin-prettier": "^1.3.0",
"typescript": "^3.0.3"
"@babel/core": "~7.10.5",
"@babel/preset-env": "~7.10.4",
"@types/common-tags": "~1.8.0",
"@types/jest": "~26.0.7",
"@types/node": "~14.0.25",
"@types/require-relative": "~0.8.0",
"babel-jest": "~26.1.0",
"codecov": "~3.7.2",
"jest": "~26.1.0",
"jest-cli": "~26.1.0",
"jest-plugin-fs": "~2.9.0",
"jest-plugins": "~2.9.0",
"prettier": "2.0.5",
"rimraf": "~3.0.2",
"ts-jest": "~26.1.3",
"typescript": "~3.9.7"
},
"engines": {
"node": ">=8.0.0"
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
"node": ">= 12.0.0",
"npm": ">= 6.14.0",
"yarn": ">= 1.22.4"
},
"homepage": "https://github.com/linterjs/core#readme",
"keywords": [
Expand All @@ -55,10 +51,11 @@
},
"scripts": {
"build": "tsc",
"check": "npm-check",
"clean": "rimraf coverage dist",
"clean:build": "rimraf dist",
"clean:test": "rimraf coverage",
"format": "prettier --write .",
"lint": "echo Currently no linter installed",
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
"prebuild": "npm run clean:build",
"prepublishOnly": "npm run build",
"pretest": "npm run clean:test",
Expand Down
3 changes: 0 additions & 3 deletions prettier.config.js

This file was deleted.

7 changes: 4 additions & 3 deletions src/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createFormat } from "./format";
import { createFormat, FormatFunction } from "./format";
import { LinterAdapter } from "./linter-adapter";

describe("Format", () => {
const filePath = "test.js";
Expand All @@ -14,8 +15,8 @@ describe("Format", () => {
});

describe("with @linter/provider-eslint", () => {
let format;
let linterAdapterPromiseList;
let format: FormatFunction;
let linterAdapterPromiseList: Array<Promise<LinterAdapter>>;

beforeAll(() => {
const { factory } = require("@linter/provider-eslint").default;
Expand Down
7 changes: 4 additions & 3 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export interface FormatOutput extends LintOutput {
output: string;
}

export type FormatFunction = (
{ filePath, text }: FormatInput,
) => Promise<FormatOutput>;
export type FormatFunction = ({
filePath,
text,
}: FormatInput) => Promise<FormatOutput>;

export function createFormat(
linterAdapterPromisesBySupportedExtensions: Map<
Expand Down
9 changes: 5 additions & 4 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export interface LintOutput {
warningCount: number;
}

export type LintFunction = (
{ filePath, text }: LintInput,
) => Promise<LintOutput>[];
export type LintFunction = ({
filePath,
text,
}: LintInput) => Promise<LintOutput>[];

export function createLint(
linterAdapterPromisesBySupportedExtensions: Map<
Expand Down Expand Up @@ -68,7 +69,7 @@ export function createLint(
for (const linterAdapterPromise of linterAdapterPromises.values()) {
// TODO: Handle error in linterFactory and lint?
lintOutput.push(
Promise.resolve(linterAdapterPromise).then(linterAdapter =>
Promise.resolve(linterAdapterPromise).then((linterAdapter) =>
linterAdapter.lint(lintArgs),
),
);
Expand Down
14 changes: 8 additions & 6 deletions src/linter-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { FormatInput, FormatOutput } from "./format";
import { LintInput, LintOutput } from "./lint";

export type LinterAdapterFormat = (
{ filePath, text }: FormatInput,
) => FormatOutput | Promise<FormatOutput>;
export type LinterAdapterFormat = ({
filePath,
text,
}: FormatInput) => FormatOutput | Promise<FormatOutput>;

export type LinterAdapterLint = (
{ filePath, text }: LintInput,
) => LintOutput | Promise<LintOutput>;
export type LinterAdapterLint = ({
filePath,
text,
}: LintInput) => LintOutput | Promise<LintOutput>;

// XXX: LinterAdapters decide if they do anything with text based on filePath and text
// Do we need to forward more info to LinterAdapters?
Expand Down
5 changes: 0 additions & 5 deletions src/linter-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import fs from "jest-plugin-fs";
import {
LinterAdapter,
LinterAdapterFormat,
LinterAdapterLint,
} from "./linter-adapter";
import { loadLinterProvidersFromFile } from "./linter-provider";

jest.mock("fs", () => require("jest-plugin-fs/mock"));
Expand Down
15 changes: 7 additions & 8 deletions src/linter-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { oneLine } from "common-tags";
import readPkgUp = require("read-pkg-up");
import requireRelative = require("require-relative");

import { oneLine } from "common-tags";
import {
LinterProviderLoadError,
ModuleNotLinterProviderError,
Expand Down Expand Up @@ -29,20 +30,18 @@ function isLinterProviderModule(
}

export function loadLinterProvidersFromFile(): Set<LinterProvider> {
const { pkg: packageJson = {} } = readPkgUp.sync({ normalize: false });
const { packageJson } = readPkgUp.sync({ normalize: false }) ?? {};

const {
dependencies = {},
devDependencies = {},
optionalDependencies = {},
} = packageJson;
const dependencies = packageJson?.dependencies ?? {};
const devDependencies = packageJson?.devDependencies ?? {};
const optionalDependencies = packageJson?.optionalDependencies ?? {};

const linterProviderModuleNames = Object.keys({
...dependencies,
...devDependencies,
...optionalDependencies,
}).filter(
dependency =>
(dependency) =>
dependency.startsWith("@linter/provider-") ||
dependency.startsWith("linter-provider-") ||
(dependency.startsWith("@") && dependency.includes("/linter-provider-")),
Expand Down
4 changes: 2 additions & 2 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createFormat, FormatFunction } from "./format";
import { createLint, LintFunction } from "./lint";
import { LinterAdapter } from "./linter-adapter";
import { loadLinterProvidersFromFile } from "./linter-provider";
import { logger, getDefaultLogLevel } from "./logger";
import { getDefaultLogLevel, logger } from "./logger";

// Create a new instance of Linter to load/reload registered
// linter providers from file
Expand All @@ -23,7 +23,7 @@ export default class Linter {
for (const { factory, supportedExtensions } of linterProviders.values()) {
const linterAdapter = Promise.resolve(factory());

new Set(supportedExtensions).forEach(extension => {
new Set(supportedExtensions).forEach((extension) => {
const extensionWithDot = extension.includes(".")
? extension
: `.${extension}`;
Expand Down
5 changes: 3 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import getLogger = require("loglevel-colored-level-prefix");
import { LogLevelDesc } from "loglevel";

export function getDefaultLogLevel() {
return process.env.LOG_LEVEL || "warn";
export function getDefaultLogLevel(): LogLevelDesc {
return (process.env.LOG_LEVEL as LogLevelDesc | undefined) ?? "warn";
}

export const logger = getLogger({ prefix: "@linter/core" });
12 changes: 12 additions & 0 deletions src/loglevel-colored-level-prefix.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module "loglevel-colored-level-prefix" {
import { Logger, LogLevelDesc } from "loglevel";

namespace log {
export interface LoggerOptions {
level?: LogLevelDesc;
prefix?: string;
}
}
function getLogger(options?: log.LoggerOptions): Logger;
export = getLogger;
}
17 changes: 5 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
{
"compileOnSave": false,
"compilerOptions": {
"declaration": true,
"downlevelIteration": true,
"importHelpers": true,
"module": "commonjs",
"noUnusedLocals": true,
"noUnusedParameters": true,
"module": "CommonJS",
"outDir": "dist",
"preserveConstEnums": true,
"removeComments": true,
"strictNullChecks": true,
"target": "es2017"
"strict": true,
"target": "ES2018"
},
"exclude": [
"node_modules",
"**/__mocks__",
"**/__snapshots__",
"**/__tests__",
"**/*.spec.*",
"**/*.test.*"
],
"include": ["./src"],
"plugins": [
{
"name": "tslint-language-service"
}
]
"include": ["src/**/*"]
}
11 changes: 0 additions & 11 deletions tslint.json

This file was deleted.

Loading