Skip to content

Commit

Permalink
Merge branch 'update'
Browse files Browse the repository at this point in the history
  • Loading branch information
levchak0910 committed Mar 30, 2024
2 parents c45945b + 4f97d84 commit 58b9ecc
Show file tree
Hide file tree
Showing 39 changed files with 5,088 additions and 7,366 deletions.
60 changes: 59 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
"plugin:@ota-meshi/+json",
"plugin:@ota-meshi/+yaml",
"plugin:@ota-meshi/+prettier",
"plugin:node-dependencies/recommended",
],
rules: {
"require-jsdoc": "off",
Expand All @@ -35,10 +36,59 @@ module.exports = {
"error",
["name", "filename", "settings", "options", "code"],
],
// Repo rule
"@typescript-eslint/no-restricted-imports": [
"error",
{
patterns: [
{
group: ["/regexpp", "/regexpp/*"],
message: "Please use `@eslint-community/regexpp` instead.",
},
{
group: ["/eslint-utils", "/eslint-utils/*"],
message: "Please use `@eslint-community/eslint-utils` instead.",
},
],
},
],
"no-restricted-properties": [
"error",
{
object: "context",
property: "getSourceCode",
message: "Use src/utils/compat.ts",
},
{
object: "context",
property: "getFilename",
message: "Use src/utils/compat.ts",
},
{
object: "context",
property: "getPhysicalFilename",
message: "Use src/utils/compat.ts",
},
{
object: "context",
property: "getCwd",
message: "Use src/utils/compat.ts",
},
{
object: "context",
property: "getScope",
message: "Use src/utils/compat.ts",
},
{
object: "context",
property: "parserServices",
message: "Use src/utils/compat.ts",
},
],
},
overrides: [
{
files: ["*.ts"],
files: ["*.ts", "*.mts"],
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-require-imports": "off",
Expand Down Expand Up @@ -98,5 +148,13 @@ module.exports = {
"no-console": "off",
},
},
{
files: ["lib/utils/**/*.js"],
rules: {
"no-shadow": "off",
"default-case": "off",
"no-restricted-properties": "off",
},
},
],
};
87 changes: 64 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on:
on:
workflow_dispatch:
pull_request:
branches:
Expand All @@ -9,44 +9,85 @@ on:
branches:
- main
tags:
- "v*.*.*"
- "v*.*.*"

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: latest

- name: Install pnpm
uses: pnpm/action-setup@v3.0.0
with:
node-version: 16
cache: 'npm'
- run: npm ci
- run: npm run lint
version: 8

- name: Install
run: pnpm install --no-frozen-lockfile

- name: Lint
run: pnpm run lint

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: latest

- name: Install pnpm
uses: pnpm/action-setup@v3.0.0
with:
node-version: 16
cache: 'npm'
- run: npm ci
- run: npm test
version: 8

- name: Install packages
run: pnpm install --no-frozen-lockfile

- name: Test
run: pnpm run test

publish:
runs-on: ubuntu-latest
needs: [eslint, tests]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: latest

- name: Install pnpm
uses: pnpm/action-setup@v3.0.0
with:
node-version: 16
cache: 'npm'
- run: npm ci
- run: npm run build
- uses: JS-DevTools/npm-publish@v3
version: 8

- name: Install packages
run: pnpm install --no-frozen-lockfile

- name: Build
run: pnpm run build

- name: Generate changelog
run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GH_TOKEN}}

- name: Publish package
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
- uses: softprops/action-gh-release@v1
token: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion lib/rules/no-convention-violation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
} from "../types";
import { getResolvedSelectors } from "../styles/selectors";
import { isDefined } from "../utils/utils";
import { getFilename } from "../utils/compat";
import type { ValidStyleContext } from "../styles/context";

export = {
Expand Down Expand Up @@ -341,7 +342,7 @@ export = {
}

function getPrefix(style: ValidStyleContext): string {
const fileName = context.getFilename();
const fileName = getFilename(context);
const { dir, name } = path.parse(fileName);

const defaultComponentName =
Expand Down
11 changes: 9 additions & 2 deletions lib/rules/no-dynamic-class-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {

import * as utils from "../utils/vue";
import { getClassAttrNameRegexp } from "../utils/class-attr";
import { getSourceCode } from "../utils/compat";
import type { RuleContext, RuleListener } from "../types";

function withProps(
Expand All @@ -26,11 +27,15 @@ function withProps(
}

return utils.compositingVisitors(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- prevent test failing
// @ts-ignore -- eslint compat types diff, fix after upgrading to eslint v9
utils.defineScriptSetupVisitor(context, {
onDefinePropsEnter(_, props) {
propNames.push(...props.map((p) => p.propName).filter(isString));
},
}) as RuleListener,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- prevent test failing
// @ts-ignore -- eslint compat types diff, fix after upgrading to eslint v9
utils.defineVueVisitor(context, {
onVueObjectEnter(node) {
const props = utils.getComponentPropsFromOptions(node);
Expand Down Expand Up @@ -69,7 +74,9 @@ export = {
type: "problem",
},
create(context: RuleContext): RuleListener {
if (!context.parserServices.defineTemplateBodyVisitor) return {};
const sourceCode = getSourceCode(context);

if (!sourceCode.parserServices.defineTemplateBodyVisitor) return {};

const classAttrRegexp = getClassAttrNameRegexp(context);
const allowConditional = context.options[0]?.allowConditional || false;
Expand Down Expand Up @@ -227,7 +234,7 @@ export = {
}

return withProps(context, (props) =>
context.parserServices.defineTemplateBodyVisitor({
sourceCode.parserServices.defineTemplateBodyVisitor({
[`VAttribute[key.name=${classAttrRegexp}]`](node: VAttribute) {
reportDynamic(node, props);
},
Expand Down
11 changes: 6 additions & 5 deletions lib/rules/no-undefined-class-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
isSatisfyList,
} from "../utils/utils";
import { getClassAttrNameRegexp, getAttrName } from "../utils/class-attr";
import { getSourceCode } from "../utils/compat";

function getAllSelectorsFromStyles(
styles: ValidStyleContext[],
Expand Down Expand Up @@ -98,7 +99,7 @@ function getClassPosition(
let startColumn = -1;

if (isMultiline) {
const classLineIndex = lines.findIndex((l) => l.includes(className))!;
const classLineIndex = lines.findIndex((l) => l.includes(className));
const classLine = lines[classLineIndex];

line = classLineIndex;
Expand Down Expand Up @@ -244,7 +245,7 @@ export = {
return {};
}
const styles = getStyleContexts(context).filter(isValidStyleContext);
const source = context.getSourceCode();
const sourceCode = getSourceCode(context);
const reporter = getCommentDirectivesReporter(context);

const classAttrRegexp = getClassAttrNameRegexp(context);
Expand Down Expand Up @@ -291,8 +292,8 @@ export = {
column: endCol!,
};

const startIndex = source.getIndexFromLoc(start);
const endIndex = source.getIndexFromLoc(end);
const startIndex = sourceCode.getIndexFromLoc(start);
const endIndex = sourceCode.getIndexFromLoc(end);

const allAvailableClasses = className.includes("--")
? Array.from(vkcnClassSelectors.keys())
Expand Down Expand Up @@ -422,7 +423,7 @@ export = {
return false;
}

return context.parserServices.defineTemplateBodyVisitor({
return sourceCode.parserServices.defineTemplateBodyVisitor({
[`VAttribute[key.name=${classAttrRegexpAsString}]`](attr: VAttribute) {
const classListString = attr.value?.value;
if (classListString === undefined) return;
Expand Down
9 changes: 5 additions & 4 deletions lib/styles/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
createStyleContexts,
StyleContext,
type StyleContext,
isValidStyleContext,
ValidStyleContext,
InvalidStyleContext,
type ValidStyleContext,
type InvalidStyleContext,
} from "./style";
import type { CommentDirectives } from "./comment-directive";
import {
Expand All @@ -17,6 +17,7 @@ import {
VueComponentContext,
createVueComponentContext,
} from "./vue-components";
import { getSourceCode } from "../../utils/compat";

type CacheValue = {
styles?: StyleContext[];
Expand All @@ -32,7 +33,7 @@ const CACHE = new WeakMap<AST.ESLintProgram, CacheValue>();
* Gets the cache.
*/
function getCache(context: RuleContext): CacheValue {
const sourceCode = context.getSourceCode();
const sourceCode = getSourceCode(context);
const { ast } = sourceCode;
if (CACHE.has(ast)) {
return CACHE.get(ast) as CacheValue;
Expand Down
16 changes: 9 additions & 7 deletions lib/styles/context/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "../../../types";
import type { VCSSStyleSheet, VCSSNode, VCSSSelectorNode } from "../../ast";
import { isVCSSContainerNode, hasSelectorNodes } from "../../utils/css-nodes";
import { getSourceCode } from "../../../utils/compat";

/**
* Check whether the program has invalid EOF or not.
Expand All @@ -18,16 +19,17 @@ function getInvalidEOFError(
inDocumentFragment: boolean;
error: AST.ParseError;
} | null {
const node = context.getSourceCode().ast;
const node = getSourceCode(context).ast;
const body = node.templateBody;
let errors = body?.errors;
let inDocumentFragment = false;
if (errors == null) {
const sourceCode = getSourceCode(context);
/* istanbul ignore if */
if (!context.parserServices.getDocumentFragment) {
if (!sourceCode.parserServices.getDocumentFragment) {
return null;
}
const df = context.parserServices.getDocumentFragment();
const df = sourceCode.parserServices.getDocumentFragment();
inDocumentFragment = true;
errors = df?.errors;
/* istanbul ignore if */
Expand Down Expand Up @@ -62,11 +64,11 @@ function getInvalidEOFError(
*/
function getStyleElements(context: RuleContext): AST.VElement[] {
let document: AST.VDocumentFragment | null = null;
if (context.parserServices.getDocumentFragment) {
const sourceCode = getSourceCode(context);
if (sourceCode.parserServices.getDocumentFragment) {
// vue-eslint-parser v7.0.0
document = context.parserServices.getDocumentFragment();
document = sourceCode.parserServices.getDocumentFragment();
} else {
const sourceCode = context.getSourceCode();
const { ast } = sourceCode;
const templateBody = ast.templateBody as AST.ESLintProgram | undefined;
/* istanbul ignore if */
Expand Down Expand Up @@ -189,7 +191,7 @@ export class StyleContextImpl {
public readonly cssNode: VCSSStyleSheet | null;

public constructor(style: AST.VElement, context: RuleContext) {
const sourceCode = context.getSourceCode();
const sourceCode = getSourceCode(context);
this.styleElement = style;
this.sourceCode = sourceCode;

Expand Down
Loading

0 comments on commit 58b9ecc

Please sign in to comment.