Skip to content

Commit

Permalink
Merge branch 'main' into release-canary
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedBaset authored Sep 27, 2024
2 parents 8a2e495 + 34e3580 commit 0f5db7b
Show file tree
Hide file tree
Showing 15 changed files with 520 additions and 110 deletions.
7 changes: 7 additions & 0 deletions .changeset/young-ties-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"eslint-plugin-rtl-friendly": minor
---

Add option `allowPhysicalInsetWithAbsolute` to allow the use of `left-1/2` with `fixed -translate-x-1/2`

Add option `debug`
8 changes: 7 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import js from "@eslint/js";
import eslintPlugin from "eslint-plugin-eslint-plugin";
import { config, configs } from "typescript-eslint";

import rtlFriendly from "./dist/index.js";
import rtlFriendly, { ruleSettings } from "./dist/index.js";

export default config(
{
Expand All @@ -25,5 +25,11 @@ export default config(
{
files: ["**/*.{tsx,jsx}"],
...rtlFriendly.configs.recommended,
rules: {
"rtl-friendly/no-physical-properties": [
"warn",
ruleSettings({ allowPhysicalInsetWithAbsolute: true }),
],
},
}
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"eslint-plugin-eslint-plugin": "^6.2.0",
"tailwindcss": "~3.3.3",
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"typescript-eslint": "^8.0.0",
"vitest": "^2.0.5"
},
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/configs/recommended.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, it } from "vitest";
import { recommended } from "./recommended.js";

describe("recommended", () => {
it("should export recommended", () => {
expect(recommended).toMatchInlineSnapshot(`
{
"rules": {
"rtl-friendly/no-physical-properties": "warn",
},
}
`);
});
});
7 changes: 7 additions & 0 deletions src/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Act as default options for rules
*/
export const FLAGS = {
allowPhysicalInsetWithAbsolute: false,
debug: false,
};
55 changes: 55 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { describe, it, expect, expectTypeOf } from "vitest";
import rtlFriendly, { ruleSettings } from "./index.js";
import { name, version } from "../package.json";
import type { Rule } from "./rules/no-phyisical-properties/rule.js";

// useless tests generated by copilot :)

describe("rtlFriendly", () => {
it("should have correct meta information", () => {
expect(rtlFriendly.meta.name).toBe(name);
expect(rtlFriendly.meta.version).toBe(version);
});

it("should have the no-physical-properties rule", () => {
expect(rtlFriendly.rules).toHaveProperty("no-physical-properties");
expectTypeOf(
rtlFriendly.rules["no-physical-properties"]
).toMatchTypeOf<Rule>();
});

describe("configs", () => {
it("should have a recommended config", () => {
expect(rtlFriendly.configs).toHaveProperty("recommended");
});

it("recommended config should have the correct rules", () => {
expect(rtlFriendly.configs.recommended.rules).toHaveProperty(
"rtl-friendly/no-physical-properties",
"warn"
);
});

it("recommended config should include the rtlFriendly plugin", () => {
expect(rtlFriendly.configs.recommended.plugins).toHaveProperty(
"rtl-friendly",
rtlFriendly
);
});

it("recommended config should have jsx enabled in parser options", () => {
expect(
rtlFriendly.configs.recommended.languageOptions?.parserOptions
?.ecmaFeatures?.jsx
).toBe(true);
});
});
});

describe("ruleSettings", () => {
it("should return the options", () => {
expect(ruleSettings({ allowPhysicalInsetWithAbsolute: true })).toEqual({
allowPhysicalInsetWithAbsolute: true,
});
});
});
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
import { name, version } from "../package.json";
import { noPhysicalProperties } from "./rules/no-phyisical-properties/rule.js";
import {
noPhysicalProperties,
ruleSettings,
} from "./rules/no-phyisical-properties/rule.js";

const rtlFriendly = {
meta: { name, version },
Expand Down Expand Up @@ -32,3 +35,5 @@ const configs = {
Object.assign(rtlFriendly.configs, configs);

export default rtlFriendly;

export { ruleSettings, rtlFriendly };
20 changes: 20 additions & 0 deletions src/rules/no-phyisical-properties/ast.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// the ast.ts exports are tested in `test.ts` but this file is only to 100% coverage

import { describe, expect, it } from "vitest";
import { extractTokensFromNode } from "./ast.js";
import type { Context } from "./rule.js";
import type { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils";

describe("ast", () => {
it("non JSXAttribute", () => {
expect(
extractTokensFromNode(
{
type: "VariableDeclaration" as AST_NODE_TYPES.VariableDeclaration,
} as TSESTree.Node,
{} as Context,
"fixer"
)
).toEqual([]);
});
});
Loading

0 comments on commit 0f5db7b

Please sign in to comment.