Skip to content

Commit

Permalink
fix: build cjs and adjust rules some more
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Mar 31, 2024
1 parent 6f02ef8 commit 72b9a18
Show file tree
Hide file tree
Showing 18 changed files with 567 additions and 362 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
},
"type": "module",
"exports": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
"types": {
"require": "./dist/index.d.cts",
"import": "./dist/index.d.mts"
},
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
"files": [
"dist/",
Expand Down
23 changes: 18 additions & 5 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ const treeshake = {
export default {
input: "src/index.ts",

output: {
file: pkg.exports.import.default,
format: "esm",
sourcemap: false,
},
output: [
{
file: pkg.exports.import,
format: "esm",
sourcemap: false,
generatedCode: {
preset: "es2015",
},
},
{
file: pkg.exports.import,
format: "esm",
sourcemap: false,
generatedCode: {
preset: "es2015",
},
},
],

plugins: [
rollupPluginAutoExternal(),
Expand Down
20 changes: 11 additions & 9 deletions src/configs/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
GLOB_TS,
GLOB_TSX,
GLOB_YAML,
} from "..";
} from "../globs";
import {
type FlatConfigItem,
type OptionsFormatters,
Expand Down Expand Up @@ -80,6 +80,7 @@ export async function formatters(
const turnOffRulesForPrettier = {
...configPrettier.rules,

"no-irregular-whitespace": "off",
"style/block-spacing": "off",
"style/brace-style": "off",
"style/comma-dangle": "off",
Expand All @@ -91,6 +92,7 @@ export async function formatters(
"style/keyword-spacing": "off",
"style/lines-around-comment": "off",
"style/member-delimiter-style": "off",
"style/newline-per-chained-call": "off",
"style/no-extra-parens": "off",
"style/no-extra-semi": "off",
"style/nonblock-statement-body-position": "off",
Expand All @@ -117,7 +119,7 @@ export async function formatters(
},
];

if (options.js !== undefined && options.js !== false) {
if (options.js !== undefined && options.js) {
configs.push({
name: "rs:formatter:javascript",
files: [GLOB_JS, GLOB_JSX],
Expand All @@ -134,7 +136,7 @@ export async function formatters(
});
}

if (options.ts !== undefined && options.ts !== false) {
if (options.ts !== undefined && options.ts) {
configs.push({
name: "rs:formatter:typescript",
files: [GLOB_TS, GLOB_TSX],
Expand All @@ -152,7 +154,7 @@ export async function formatters(
});
}

if (options.yaml !== undefined && options.yaml !== false) {
if (options.yaml !== undefined && options.yaml) {
configs.push({
name: "rs:formatter:yaml",
files: [GLOB_YAML],
Expand All @@ -173,7 +175,7 @@ export async function formatters(
});
}

if (options.json !== undefined && options.json !== false) {
if (options.json !== undefined && options.json) {
configs.push(
{
name: "rs:formatter:json",
Expand Down Expand Up @@ -253,7 +255,7 @@ export async function formatters(
);
}

if (options.css !== undefined && options.css !== false) {
if (options.css !== undefined && options.css) {
configs.push(
{
name: "rs:formatter:css",
Expand Down Expand Up @@ -309,7 +311,7 @@ export async function formatters(
);
}

if (options.html !== undefined && options.html !== false) {
if (options.html !== undefined && options.html) {
configs.push({
name: "rs:formatter:html",
files: ["**/*.html"],
Expand All @@ -329,7 +331,7 @@ export async function formatters(
});
}

if (options.markdown !== undefined && options.markdown !== false) {
if (options.markdown !== undefined && options.markdown) {
const GLOB_SLIDEV =
options.slidev === undefined || options.slidev === false
? []
Expand Down Expand Up @@ -382,7 +384,7 @@ export async function formatters(
}
}

if (options.graphql !== undefined && options.graphql !== false) {
if (options.graphql !== undefined && options.graphql) {
configs.push({
files: [GLOB_GRAPHQL],
languageOptions: {
Expand Down
8 changes: 3 additions & 5 deletions src/configs/functional.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { type ESLint } from "eslint";

import { GLOB_TS } from "../globs";
import {
type FlatConfigItem,
Expand Down Expand Up @@ -28,8 +26,8 @@ export async function functional(
}

const [pluginFunctional] = (await loadPackages([
"eslint-plugin-functional/flat",
])) as [(typeof import("eslint-plugin-functional/flat"))["default"]];
"eslint-plugin-functional",
])) as [(typeof import("eslint-plugin-functional"))["default"]];

const strictRules = {
"functional/functional-parameters": "error",
Expand Down Expand Up @@ -209,7 +207,7 @@ export async function functional(
{
name: "rs:functional",
plugins: {
functional: pluginFunctional as unknown as ESLint.Plugin,
functional: pluginFunctional,
},
settings: {
immutability: {
Expand Down
13 changes: 10 additions & 3 deletions src/configs/ignores.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { GLOB_EXCLUDE } from "../globs";
import { type FlatConfigItem } from "../types";
import { type FlatConfigItem, type OptionsIgnores } from "../types";

export function ignores(options: Readonly<OptionsIgnores>): FlatConfigItem[] {
const [extend, files] =
options === undefined || Array.isArray(options)
? [true, options ?? []]
: [options.extend ?? true, options.files ?? []];

const ignores = extend ? [...GLOB_EXCLUDE, ...files] : [...files];

export function ignores(): FlatConfigItem[] {
return [
{
ignores: GLOB_EXCLUDE,
ignores,
},
];
}
4 changes: 2 additions & 2 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ESLint } from "eslint";

import { GLOB_DTS, GLOB_MJS, GLOB_MTS, GLOB_TS, GLOB_TSX } from "..";
import { GLOB_DTS, GLOB_MJS, GLOB_MTS, GLOB_TS, GLOB_TSX } from "../globs";
import { type FlatConfigItem, type OptionsStylistic } from "../types";
import { loadPackages } from "../utils";

Expand Down Expand Up @@ -107,7 +107,7 @@ export async function imports(
"import/no-self-import": "error",
"import/no-unassigned-import": "error",
// "import/no-unused-modules": "off",
"import/no-unresolved": "error",
// "import/no-unresolved": "off",
"import/no-useless-path-segments": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./jsdoc";
export * from "./jsonc";
export * from "./markdown";
export * from "./node";
export * from "./overrides";
export * from "./sort";
export * from "./stylistic";
export * from "./test";
Expand Down
27 changes: 6 additions & 21 deletions src/configs/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type ESLint } from "eslint";
import globals from "globals";

import { GLOB_SRC, GLOB_SRC_EXT } from "../globs";
import {
type FlatConfigItem,
type OptionsFunctional,
Expand Down Expand Up @@ -380,29 +379,15 @@ export async function javascript(

...(functionalEnforcement === "none"
? {}
: {
"no-param-reassign": "error",
"sonar/elseif-without-else": "error",
}),
: functionalEnforcement === "lite"
? { "no-param-reassign": "error" }
: {
"no-param-reassign": "error",
"sonar/elseif-without-else": "error",
}),

...overrides,
},
},
{
files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`],
name: "rs:scripts-overrides",
rules: {
"no-console": "off",

"functional/no-conditional-statements": "off",
"functional/no-expression-statements": "off",
"functional/no-loop-statements": "off",
"functional/no-return-void": "off",
"functional/no-throw-statements": "off",

"node/no-sync": "off",
"node/no-unpublished-import": "off",
},
},
];
}
63 changes: 37 additions & 26 deletions src/configs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
GLOB_MARKDOWN,
GLOB_MARKDOWN_CODE,
GLOB_MARKDOWN_IN_MARKDOWN,
} from "..";
} from "../globs";
import {
type FlatConfigItem,
type OptionsComponentExts,
Expand All @@ -31,9 +31,7 @@ export async function markdown(
interopDefault(import("@typescript-eslint/eslint-plugin")).catch(
() => undefined,
),
interopDefault(import("eslint-plugin-functional/flat")).catch(
() => undefined,
),
interopDefault(import("eslint-plugin-functional")).catch(() => undefined),
]);

return [
Expand Down Expand Up @@ -71,6 +69,7 @@ export async function markdown(
],
languageOptions: {
parserOptions: {
project: null,
ecmaFeatures: {
impliedStrict: true,
},
Expand All @@ -80,49 +79,61 @@ export async function markdown(
...pluginTs?.configs["disable-type-checked"]?.rules,
...pluginFunctional?.configs.off.rules,

"import/newline-after-import": "off",
"dot-notation": "off",
"init-declarations": "off",
"no-alert": "off",
"no-console": "off",
"no-empty-function": "off",
"no-empty": "off",
"no-irregular-whitespace": "off",
"no-invalid-this": "off",
"no-labels": "off",
"no-lone-blocks": "off",
"no-restricted-syntax": "off",
"no-throw-literal": "off",
"no-undef": "off",
"no-unused-expressions": "off",
"no-unused-labels": "off",
"no-unused-vars": "off",
"node/prefer-global/process": "off",
"style/comma-dangle": "off",
"style/eol-last": "off",
"ts/consistent-type-imports": "off",
"ts/no-namespace": "off",
"ts/no-redeclare": "off",
"ts/no-require-imports": "off",
"ts/no-unused-vars": "off",
"ts/no-use-before-define": "off",
"ts/no-var-requires": "off",
"no-useless-return": "off",
"prefer-const": "off",
"unicode-bom": "off",
"dot-notation": "off",

"import/extensions": "off",
"import/newline-after-import": "off",
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "off",
"init-declarations": "off",

"jsdoc/require-jsdoc": "off",
"n/handle-callback-err": "off",
"no-empty-function": "off",
"no-empty": "off",
"no-invalid-this": "off",
"no-throw-literal": "off",
"no-useless-return": "off",
"prefer-const": "off",

"node/handle-callback-err": "off",
"node/prefer-global/process": "off",

"prettier/prettier": "off",
"sonarjs/no-extra-arguments": "off",
"sonarjs/no-unused-collection": "off",

"sonar/no-extra-arguments": "off",
"sonar/no-unused-collection": "off",

"style/comma-dangle": "off",
"style/eol-last": "off",

"ts/consistent-generic-constructors": "off",
"ts/consistent-indexed-object-style": "off",
"ts/consistent-type-definitions": "off",
"ts/consistent-type-imports": "off",
"ts/explicit-member-accessibility": "off",
"ts/no-empty-function": "off",
"ts/no-explicit-any": "off",
"ts/no-namespace": "off",
"ts/no-redeclare": "off",
"ts/no-require-imports": "off",
"ts/no-unused-expressions": "off",
"ts/no-unused-vars": "off",
"ts/no-use-before-define": "off",
"ts/no-var-requires": "off",
"ts/prefer-for-of": "off",
"ts/prefer-function-type": "off",

"unicorn/prefer-optional-catch-binding": "off",
"unicorn/prefer-top-level-await": "off",
"unicorn/switch-case-braces": "off",
Expand Down
Loading

0 comments on commit 72b9a18

Please sign in to comment.