Skip to content

Commit

Permalink
feat: more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jul 29, 2024
1 parent 1fb3566 commit 9590db4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { rollupPlugin as rollupPluginDeassert } from "deassert";
import { type RollupOptions } from "rollup";
import rollupPluginTs from "rollup-plugin-ts";

import pkg from "./package.json" assert { type: "json" };
import pkg from "./package.json" with { type: "json" };

const treeshake = {
annotations: true,
Expand Down
5 changes: 5 additions & 0 deletions scripts/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const configs = (await combine(
}),
markdown({
files: [],
enableTypeRequiredRules: false,
componentExts: [],
overrides: undefined,
}),
Expand Down Expand Up @@ -107,6 +108,8 @@ const configs = (await combine(
unsafe: "off",
functionalEnforcement: "none",
ignoreNamePattern: [],
projectRoot: process.cwd(),
mode: "none",
}),
unicorn(),
unocss({
Expand All @@ -122,6 +125,8 @@ const configs = (await combine(
typescript: false,
stylistic: false,
files: [],
filesTypeAware: [],
parserOptions: {},
}),
yaml({
overrides: undefined,
Expand Down
31 changes: 17 additions & 14 deletions src/configs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import {
type OptionsComponentExts,
type OptionsFiles,
type OptionsOverrides,
type OptionsTypeRequiredRules,
} from "../types";
import { interopDefault, loadPackages, parserPlain } from "../utils";

export async function markdown(
options: Readonly<
Required<OptionsFiles & OptionsComponentExts & OptionsOverrides>
Required<
OptionsFiles &
OptionsComponentExts &
OptionsTypeRequiredRules &
OptionsOverrides
>
>,
): Promise<FlatConfigItem[]> {
const { componentExts, files, overrides } = options;
const enableTypeRequiredRules = false as boolean; // TODO: finish setting up.
const { componentExts, files, overrides, enableTypeRequiredRules } = options;

const [pluginMarkdown] = (await loadPackages(["eslint-plugin-markdown"])) as [
ESLint.Plugin,
Expand Down Expand Up @@ -61,30 +66,28 @@ export async function markdown(
},
},
{
name: "rs:markdown:disables",
name: "rs:markdown:code",
files: [
GLOB_MARKDOWN_CODE,
...componentExts.map((ext) => `${GLOB_MARKDOWN}/**/*.${ext}`),
...componentExts.map((ext) => `${GLOB_MARKDOWN}/*.${ext}`),
],
languageOptions: {
parserOptions: {
...(enableTypeRequiredRules
? {}
: {
project: false,
projectService: false,
program: null,
}),
? undefined
: { project: false, projectService: false, program: null }),
ecmaFeatures: {
impliedStrict: true,
},
},
},
rules: {
...(enableTypeRequiredRules
? {}
: pluginTs?.configs["disable-type-checked"]?.rules),
...pluginFunctional?.configs.off.rules,
? undefined
: {
...pluginTs?.configs["disable-type-checked"]?.rules,
...pluginFunctional?.configs.off.rules,
}),

"dot-notation": "off",
"init-declarations": "off",
Expand Down
13 changes: 9 additions & 4 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ export function rsEslint(
OptionsTypeScriptParserOptions &
OptionsTypeScriptShorthands;

const projectServiceUserConfig =
typeof parserOptions?.projectService === "object"
const projectServiceUserConfig = {
defaultProject: "./tsconfig.json",
...(typeof parserOptions?.projectService === "object"
? parserOptions.projectService
: {};
: undefined),
};

const typescriptConfigOptions: Required<OptionsTypeScriptParserOptions> = {
...typeScriptSubOptions,
Expand All @@ -154,7 +156,6 @@ export function rsEslint(
: useDefaultDefaultProject === false
? projectServiceUserConfig
: {
defaultProject: "./tsconfig.json",
allowDefaultProject: [
path.join(projectRoot, GLOB_ROOT_JS),
path.join(projectRoot, GLOB_ROOT_JSX),
Expand Down Expand Up @@ -310,6 +311,10 @@ export function rsEslint(
if (markdownOptions !== false) {
m_configs.push(
markdown({
enableTypeRequiredRules:
typeof options.markdown === "boolean"
? options.markdown
: (options.markdown?.enableTypeRequiredRules ?? false),
files: [GLOB_MARKDOWN],
componentExts,
overrides: getOverrides(options, "markdown"),
Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export type OptionsHasTypeScript = {
typescript?: boolean;
};

export type OptionsTypeRequiredRules = {
enableTypeRequiredRules?: boolean;
};

export type OptionsStylistic = {
stylistic?: StylisticConfig | false;
};
Expand Down Expand Up @@ -257,7 +261,7 @@ export type OptionsConfig = {
*
* For formatting Markdown content, enable also `formatters.markdown`.
*/
markdown?: boolean | OptionsOverrides;
markdown?: boolean | (OptionsOverrides & OptionsTypeRequiredRules);

/**
* Enable stylistic rules.
Expand Down

0 comments on commit 9590db4

Please sign in to comment.