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

fix: make xo happy #145

Merged
merged 7 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 18
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
2 changes: 1 addition & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const level = (() => {
if (navigator.userAgentData) {
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
if (brand?.version > 93) {
if (brand && brand.version > 93) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see how this fixes or improves anything, what was the XO error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see how this fixes or improves anything, what was the XO error?

Error - Optional chainings are not supported until Node.js 14.0.0. The configured version range is '^12.17.0 || ^14.13 || >=16.0.0'. (n/no-unsupported-features/es-syntax)

return 3;
}
}
Expand Down
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {WriteStream} from 'node:tty';
import type {WriteStream} from 'node:tty';

export interface Options {
export type Options = {
/**
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.

@default true
*/
readonly sniffFlags?: boolean;
}
};

/**
Levels:
Expand All @@ -21,7 +21,7 @@ export type ColorSupportLevel = 0 | 1 | 2 | 3;
/**
Detect whether the terminal supports color.
*/
export interface ColorSupport {
export type ColorSupport = {
Copy link
Member

Choose a reason for hiding this comment

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

This is not the same. What was the XO error message about?

Copy link
Contributor Author

@idranme idranme Dec 7, 2022

Choose a reason for hiding this comment

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

This is not the same. What was the XO error message about?

Use a type instead of an interface. @typescript-eslint/consistent-type-definitions

/**
The color level.
*/
Expand All @@ -41,7 +41,7 @@ export interface ColorSupport {
Whether Truecolor 16 million colors are supported.
*/
has16m: boolean;
}
};

export type ColorInfo = ColorSupport | false;

Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from 'node:os';
import tty from 'node:tty';

// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see this as an improvement. What was the XO error?

Copy link
Contributor Author

@idranme idranme Dec 7, 2022

Choose a reason for hiding this comment

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

I don't see this as an improvement. What was the XO error?

line 6, col 46, Error - Optional chainings are not supported until Node.js 14.0.0. The configured version range is '^12.17.0 || ^14.13 || >=16.0.0'. (n/no-unsupported-features/es-syntax)
line 6, col 53, Error - Nullish coalescing operators are not supported until Node.js 14.0.0. The configured version range is '^12.17.0 || ^14.13 || >=16.0.0'. (n/no-unsupported-features/es-syntax)

const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf('--');
Expand Down Expand Up @@ -138,10 +138,13 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);

switch (env.TERM_PROGRAM) {
case 'iTerm.app':
case 'iTerm.app': {
return version >= 3 ? 3 : 2;
case 'Apple_Terminal':
}

Copy link
Member

Choose a reason for hiding this comment

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

Was this an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was this an error?

Error - Missing braces in case clause. (unicorn/switch-case-braces)

case 'Apple_Terminal': {
return 2;
}
// No default
}
}
Expand Down
3 changes: 2 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {stdout, stderr} from 'node:process';
import {expectType} from 'tsd';
import supportsColor, {createSupportsColor, Options, ColorInfo} from './index.js';
import type {Options, ColorInfo} from './index.d';
import supportsColor, {createSupportsColor} from './index.js';
Copy link
Member

Choose a reason for hiding this comment

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

This should be a single import


const options: Options = {};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
"import-fresh": "^3.3.0",
"tsd": "^0.18.0",
"typescript": "^4.4.3",
"xo": "^0.44.0"
"xo": "^0.53.1"
}
}