Skip to content

Commit

Permalink
chore: match main repo linting config and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Aug 8, 2024
1 parent 88b6c0c commit 47d362e
Show file tree
Hide file tree
Showing 45 changed files with 569 additions and 342 deletions.
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.cjs

This file was deleted.

42 changes: 29 additions & 13 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
"files": {
"ignore": [
"**/dist/**/*",
Expand All @@ -15,26 +15,42 @@
"ignoreUnknown": true
},
"formatter": {
"lineWidth": 100
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 100,
"ignore": [".changeset", "pnpm-lock.yaml", "*.astro"]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": false
},
"javascript": {
"formatter": {
"trailingCommas": "all",
"quoteStyle": "single",
"trailingComma": "all"
"semicolons": "always"
}
},
"json": {
"formatter": {
"indentStyle": "space"
},
"parser": {
"allowComments": true
"allowComments": true,
"allowTrailingCommas": true
},
"formatter": {
"indentStyle": "space",
"trailingCommas": "none"
}
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": false
}
"overrides": [
{
"include": ["package.json"],
"json": {
"formatter": {
"lineWidth": 1
}
}
}
]
}
126 changes: 126 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import tseslint from 'typescript-eslint';

// plugins
import regexpEslint from 'eslint-plugin-regexp';
const typescriptEslint = tseslint.plugin;

// parsers
const typescriptParser = tseslint.parser;

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default [
// If ignores is used without any other keys in the configuration object, then the patterns act as global ignores.
// ref: https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
{
ignores: [
'**/dist',
'**/node_modules',
'**/fixtures',
'**/fixture',
'**/.vscode-test',
'.github',
'.changeset',
],
},

...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
regexpEslint.configs['flat/recommended'],
{
languageOptions: {
parser: typescriptParser,
parserOptions: {
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
},
},
plugins: {
'@typescript-eslint': typescriptEslint,
regexp: regexpEslint,
},
rules: {
// These off/configured-differently-by-default rules fit well for us
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-shadow': 'error',
'no-console': ['warn', { allow: ['warn', 'error', 'info', 'debug'] }],

// Todo: do we want these?
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/class-literal-property-style': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-explicit-any': 'off',

// Enforce separate type imports for type-only imports to avoid bundling unneeded code
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
disallowTypeAnnotations: false,
},
],

// These rules enabled by the preset configs don't work well for us
'@typescript-eslint/await-thenable': 'off',
'prefer-const': 'off',

// In some cases, using explicit letter-casing is more performant than the `i` flag
'regexp/use-ignore-case': 'off',
'regexp/prefer-regexp-exec': 'warn',
'regexp/prefer-regexp-test': 'warn',
},
},

{
files: [
'packages/ts-plugin/test/**/*',
'packages/vscode/test/**/*',
// The language server is distributed as CJS in the VS Code extension, despite being written as ESM.
// As such, sometimes require are required.
'packages/language-server/**/*',
],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
];
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
"test": "turbo run test --filter=\"@astrojs/**\" --filter=astro-vscode",
"test:skip-vs": "turbo run test --filter=\"@astrojs/language-server\" --filter=\"@astrojs/check\"",
"format:ci": "pnpm run format",
"format": "biome check --apply ./ && prettier -w \"**/*\" --ignore-unknown --cache",
"lint": "eslint . --ext .js,.ts,.mjs,.cjs"
"format": "biome check --write ./ && prettier -w \"**/*\" --ignore-unknown --cache",
"lint": "eslint ."
},
"devDependencies": {
"@biomejs/biome": "1.6.0",
"@biomejs/biome": "1.8.1",
"@changesets/cli": "^2.26.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
"prettier": "^3.2.5",
"turbo": "1.10.2",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"eslint": "^9.8.0",
"typescript-eslint": "^8.0.1",
"eslint-plugin-regexp": "^2.6.0"
},
"engines": {
"node": ">=16.12.0",
Expand All @@ -34,7 +34,12 @@
"packageManager": "[email protected]",
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": ["vue", "vite", "svelte", "@babel/core"]
"ignoreMissing": [
"vue",
"vite",
"svelte",
"@babel/core"
]
}
}
}
6 changes: 5 additions & 1 deletion packages/astro-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"bin": {
"astro-check": "./dist/bin.js"
},
"files": ["bin", "dist/**/*.js", "dist/**/*.d.ts"],
"files": [
"bin",
"dist/**/*.js",
"dist/**/*.d.ts"
],
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/bin/nodeServer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
if (process.argv.includes('--version')) {
const pkgJSON = require('../package.json');
console.log(`${pkgJSON['version']}`);
console.info(`${pkgJSON['version']}`);
} else {
require('../dist/nodeServer.js');
}
7 changes: 6 additions & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
},
"type": "commonjs",
"main": "dist/index.js",
"files": ["bin", "dist/**/*.js", "dist/**/*.d.ts", "types/**/*.d.ts"],
"files": [
"bin",
"dist/**/*.js",
"dist/**/*.d.ts",
"types/**/*.d.ts"
],
"bin": {
"astro-ls": "./bin/nodeServer.js"
},
Expand Down
11 changes: 8 additions & 3 deletions packages/language-server/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'node:path';
import type { DiagnosticMessage } from '@astrojs/compiler/types';
import type { DiagnosticMessage, DiagnosticSeverity } from '@astrojs/compiler/types';
import {
type CodeMapping,
type LanguagePlugin,
Expand All @@ -12,7 +12,8 @@ import type { HTMLDocument } from 'vscode-html-languageservice';
import type { URI } from 'vscode-uri';
import { type AstroInstall, getLanguageServerTypesDir } from '../utils.js';
import { astro2tsx } from './astro2tsx';
import { AstroMetadata, getAstroMetadata } from './parseAstro';
import type { AstroMetadata } from './parseAstro';
import { getAstroMetadata } from './parseAstro';
import { extractStylesheets } from './parseCSS';
import { parseHTML } from './parseHTML';
import { extractScriptTags } from './parseJS.js';
Expand Down Expand Up @@ -184,6 +185,10 @@ export class AstroVirtualCode implements VirtualCode {
}

get hasCompilationErrors(): boolean {
return this.compilerDiagnostics.filter((diag) => diag.severity === 1).length > 0;
return (
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
this.compilerDiagnostics.filter((diag) => diag.severity === (1 satisfies DiagnosticSeverity))
.length > 0
);
}
}
3 changes: 2 additions & 1 deletion packages/language-server/src/core/parseCSS.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TSXExtractedStyle } from '@astrojs/compiler/types';
import type { CodeInformation, VirtualCode } from '@volar/language-core';
import { Segment, toString } from 'muggle-string';
import type { Segment } from 'muggle-string';
import { toString } from 'muggle-string';
import { buildMappings } from '../buildMappings.js';

const SUPPORTED_LANGUAGES = ['css', 'scss', 'less'] as const;
Expand Down
3 changes: 2 additions & 1 deletion packages/language-server/src/core/parseJS.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TSXExtractedScript } from '@astrojs/compiler/types';
import type { CodeInformation, VirtualCode } from '@volar/language-core';
import { Segment, toString } from 'muggle-string';
import type { Segment } from 'muggle-string';
import { toString } from 'muggle-string';
import { buildMappings } from '../buildMappings';

export function extractScriptTags(scripts: TSXExtractedScript[]): VirtualCode[] {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function classNameFromFilename(filename: string): string {
const withoutInvalidCharacters = withoutExtensions
.split('')
// Although "-" is invalid, we leave it in, pascal-case-handling will throw it out later
.filter((char) => /[A-Za-z$_\d-]/.test(char))
.filter((char) => /[\w$-]/.test(char))
.join('');
const firstValidCharIdx = withoutInvalidCharacters
.split('')
Expand All @@ -76,7 +76,7 @@ export function patchTSX(code: string, filePath: string) {
const basename = filePath.split('/').pop()!;
const isDynamic = basename.startsWith('[') && basename.endsWith(']');

return code.replace(/\b(\S*)__AstroComponent_/gm, (fullMatch, m1: string) => {
return code.replace(/\b(\S*)__AstroComponent_/g, (fullMatch, m1: string) => {
// If we don't have a match here, it usually means the file has a weird name that couldn't be expressed with valid identifier characters
if (!m1) {
if (basename === '404') return 'FourOhFour';
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/importPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getPackagePath(
return root
? dirname(require.resolve(packageName + '/package.json', { paths }))
: require.resolve(packageName, { paths });
} catch (e) {
} catch {
return undefined;
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/language-server/src/languageServerPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
import type {
Connection,
LanguagePlugin,
LanguageServiceEnvironment,
MessageType,
ShowMessageNotification,
} from '@volar/language-server/node';
import { MessageType, ShowMessageNotification } from '@volar/language-server/node';
import { URI } from 'vscode-uri';
import { getAstroLanguagePlugin } from './core';
import { getSvelteLanguagePlugin } from './core/svelte.js';
Expand Down
Loading

0 comments on commit 47d362e

Please sign in to comment.