Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ jobs:
cd clients/algoliasearch-client-javascript/packages
ls | grep -v -E "(client-common|requester-*|algoliasearch)" | xargs rm -rf
cd algoliasearch
ls | grep -v -E "(__tests__|jest.config.ts)" | xargs rm -rf
ls | grep -v -E "__tests__" | xargs rm -rf

- name: Setup
uses: ./.github/actions/setup
Expand Down
13 changes: 0 additions & 13 deletions eslint/babel.config.cjs

This file was deleted.

7 changes: 0 additions & 7 deletions eslint/jest.config.cjs

This file was deleted.

19 changes: 10 additions & 9 deletions eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
"name": "eslint-plugin-automation-custom",
"version": "1.0.0",
"description": "Custom rules for eslint",
"main": "dist/index.js",
"type": "module",
"main": "dist/index.cjs",
"files": [
"src/**.ts"
],
"scripts": {
"build": "esbuild --bundle --minify --platform=node --outdir=dist --log-level=error src/index.ts",
"build": "esbuild --bundle --minify --platform=node --outdir=dist --out-extension:.js=.cjs --log-level=error src/index.ts",
"lint": "eslint --ext=ts .",
"lint:fix": "eslint --ext=ts --fix .",
"test": "jest"
"test": "tsc --noEmit && vitest"
},
"devDependencies": {
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.4",
"@babel/preset-typescript": "7.24.7",
"@types/jest": "29.5.13",
"@types/eslint": "9.6.1",
"esbuild": "0.23.1",
"eslint": "8.57.0",
"jest": "29.7.0",
"typescript": "5.6.2"
"eslint-plugin-yml": "1.14.0",
"eslint-vitest-rule-tester": "0.6.1",
"typescript": "5.6.2",
"vitest": "2.1.1",
"yaml-eslint-parser": "1.2.3"
}
}
16 changes: 8 additions & 8 deletions eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { endWithDot } from './rules/endWithDot';
import { noFinalDot } from './rules/noFinalDot';
import { noNewLine } from './rules/noNewLine';
import { createOutOfLineRule } from './rules/outOfLineRule';
import { refCommon } from './rules/refCommon';
import { singleQuoteRef } from './rules/singleQuoteRef';
import { validACL } from './rules/validACL';
import { validInlineTitle } from './rules/validInlineTitle';
import { endWithDot } from './rules/endWithDot.js';
import { noFinalDot } from './rules/noFinalDot.js';
import { noNewLine } from './rules/noNewLine.js';
import { createOutOfLineRule } from './rules/outOfLineRule.js';
import { refCommon } from './rules/refCommon.js';
import { singleQuoteRef } from './rules/singleQuoteRef.js';
import { validACL } from './rules/validACL.js';
import { validInlineTitle } from './rules/validInlineTitle.js';

const rules = {
'end-with-dot': endWithDot,
Expand Down
15 changes: 10 additions & 5 deletions eslint/src/rules/endWithDot.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import type { Rule } from 'eslint';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isBlockScalar, isPairWithKey, isScalar } from '../utils';
import { isBlockScalar, isPairWithKey, isScalar } from '../utils.js';

export const endWithDot: Rule.RuleModule = {
export const endWithDot = createRule('endWithDot', {
meta: {
docs: {
description: '`description` must end with a period',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
endWithDot: 'description does not end with a period',
},
fixable: 'code',
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices?.isYAML) {
return {};
}

Expand Down Expand Up @@ -52,4 +57,4 @@ export const endWithDot: Rule.RuleModule = {
},
};
},
};
});
15 changes: 10 additions & 5 deletions eslint/src/rules/noFinalDot.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import type { Rule } from 'eslint';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isPairWithKey, isScalar } from '../utils';
import { isPairWithKey, isScalar } from '../utils.js';

export const noFinalDot: Rule.RuleModule = {
export const noFinalDot = createRule('noFinalDot', {
meta: {
docs: {
description: '`summary` must not end with a period',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
noFinalDot: 'summary ends with a period',
},
fixable: 'code',
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices.isYAML) {
return {};
}

Expand Down Expand Up @@ -46,4 +51,4 @@ export const noFinalDot: Rule.RuleModule = {
},
};
},
};
});
19 changes: 12 additions & 7 deletions eslint/src/rules/outOfLineRule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Rule } from 'eslint';
import { RuleModule } from 'eslint-plugin-yml/lib/types.js';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isNullable, isPairWithKey } from '../utils';
import { isNullable, isPairWithKey } from '../utils.js';

export function createOutOfLineRule({
property,
Expand All @@ -12,18 +13,23 @@ export function createOutOfLineRule({
description?: string;
messageId?: string;
message?: string;
}): Rule.RuleModule {
const rule: Rule.RuleModule = {
}): RuleModule {
return createRule(`${property}OutOfLine`, {
meta: {
docs: {
description,
categories: null,
extensionRule: false,
layout: false,
},
messages: {
[messageId]: message,
},
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices.isYAML) {
return {};
}

Expand Down Expand Up @@ -59,6 +65,5 @@ export function createOutOfLineRule({
},
};
},
};
return rule;
});
}
17 changes: 11 additions & 6 deletions eslint/src/rules/refCommon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Rule } from 'eslint';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isPairWithKey, isScalar } from '../utils';
import { isPairWithKey, isScalar } from '../utils.js';

const allSpecs = [
'abtesting',
Expand All @@ -15,18 +15,23 @@ const allSpecs = [
'search',
];

export const refCommon: Rule.RuleModule = {
export const refCommon = createRule('refCommon', {
meta: {
docs: {
description:
'the $ref must target the current spec, or the common spec. If you intended to use a model from an other spec, move it to the common folder',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
refCommon: '$ref to another spec',
},
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices.isYAML) {
return {};
}

Expand All @@ -45,7 +50,7 @@ export const refCommon: Rule.RuleModule = {
return;
}

const spec = context.filename.match(/specs\/([a-z-]+?)\//)?.[1];
const spec = context.getFilename().match(/specs\/([a-z-]+?)\//)?.[1];
if (!spec) {
return;
}
Expand All @@ -63,4 +68,4 @@ export const refCommon: Rule.RuleModule = {
},
};
},
};
});
15 changes: 10 additions & 5 deletions eslint/src/rules/singleQuoteRef.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import type { Rule } from 'eslint';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isBlockScalar, isPairWithKey, isScalar } from '../utils';
import { isBlockScalar, isPairWithKey, isScalar } from '../utils.js';

export const singleQuoteRef: Rule.RuleModule = {
export const singleQuoteRef = createRule('singleQuoteRef', {
meta: {
docs: {
description: '$ref must be wrapped in single quote',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
refNoQuote: '$ref is not wrapped in single quote',
},
fixable: 'code',
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices.isYAML) {
return {};
}

Expand Down Expand Up @@ -52,4 +57,4 @@ export const singleQuoteRef: Rule.RuleModule = {
},
};
},
};
});
15 changes: 10 additions & 5 deletions eslint/src/rules/validACL.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Rule } from 'eslint';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isPairWithKey, isScalar } from '../utils';
import { isPairWithKey, isScalar } from '../utils.js';

const ACLs = [
'search',
Expand All @@ -19,19 +19,24 @@ const ACLs = [
'admin',
];

export const validACL: Rule.RuleModule = {
export const validACL = createRule('validACL', {
meta: {
docs: {
description: 'x-acl enum must contains valid Algolia ACLs',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
validString: 'is not a string',
validACL: `{{entry}} is not a valid Algolia ACL, must be one of: ${ACLs.join(', ')}.`,
validArray: 'is not an array of string',
},
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices.isYAML) {
return {};
}

Expand Down Expand Up @@ -75,4 +80,4 @@ export const validACL: Rule.RuleModule = {
},
};
},
};
});
17 changes: 11 additions & 6 deletions eslint/src/rules/validInlineTitle.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import type { Rule } from 'eslint';
import { createRule } from 'eslint-plugin-yml/lib/utils';

import { isNullable, isPairWithKey } from '../utils';
import { isNullable, isPairWithKey } from '../utils.js';

export const validInlineTitle: Rule.RuleModule = {
export const validInlineTitle = createRule('validInlineTitle', {
meta: {
docs: {
description: 'title must be set in inline models, should be the first property and start with a lowercase',
categories: null,
extensionRule: false,
layout: false,
},
messages: {
inlineTitleExists: 'title must be set in inline models',
lowercaseTitle: 'title must start with a lowercase',
firstProperty: 'title must be the first property',
noSpaceInTitle: 'title must not contain spaces',
},
type: 'layout',
schema: [],
},
create(context) {
if (!context.sourceCode.parserServices.isYAML) {
if (!context.getSourceCode().parserServices.isYAML) {
return {};
}

Expand Down Expand Up @@ -44,7 +49,7 @@ export const validInlineTitle: Rule.RuleModule = {
// make sure title doesn't contain spaces
if (titleValue?.includes(' ')) {
context.report({
node: title,
node: title!,
messageId: 'noSpaceInTitle',
});
}
Expand Down Expand Up @@ -85,4 +90,4 @@ export const validInlineTitle: Rule.RuleModule = {
},
};
},
};
});
Loading