Skip to content

Commit

Permalink
vs lint work on js code
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-zhang-at-salesforce committed May 13, 2024
1 parent c6516ad commit 140ba21
Show file tree
Hide file tree
Showing 28 changed files with 1,473 additions and 15 deletions.
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"overrides": [
{
"files": ["*.js"],
"processor": "@graphql-eslint/graphql"
},
{
"files": ["*.graphql"],
"parser": "@graphql-eslint/eslint-plugin",
"plugins": ["@graphql-eslint"],
"parserOptions": {
"skipGraphQLConfig": true
},
"rules": {
"@graphql-eslint/no-duplicate-fields": "error"
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/reports
test-report.xml
junit.xml
/dist

4 changes: 4 additions & 0 deletions dist/configs/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const _default: {
plugins: string[];
};
export = _default;
4 changes: 4 additions & 0 deletions dist/configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
module.exports = {
plugins: ['@salesforce/lwc-mobile']
};
8 changes: 8 additions & 0 deletions dist/configs/recommended.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const _default: {
extends: string[];
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': "warn";
'@salesforce/lwc-mobile/no-more-than-2-fields': "warn";
};
};
export = _default;
8 changes: 8 additions & 0 deletions dist/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
module.exports = {
extends: ['./configs/base'],
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': 'warn',
'@salesforce/lwc-mobile/no-more-than-2-fields': 'warn'
}
};
19 changes: 19 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare const _default: {
rules: {
'enforce-foo-bar': import("@typescript-eslint/utils/ts-eslint").RuleModule<"messageIdForFooMustBeBar", [], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
'no-more-than-2-fields': import("@graphql-eslint/eslint-plugin").GraphQLESLintRule;
};
configs: {
base: {
plugins: string[];
};
recommended: {
extends: string[];
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': "warn";
'@salesforce/lwc-mobile/no-more-than-2-fields': "warn";
};
};
};
};
export = _default;
24 changes: 24 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const base_js_1 = __importDefault(require("./configs/base.js"));
const recommended_js_1 = __importDefault(require("./configs/recommended.js"));
const enforce_foo_bar_js_1 = __importDefault(require("./rules/dummy/enforce-foo-bar.js"));
const no_more_than_2_fields_js_1 = require("./rules/graphql/no-more-than-2-fields.js");
module.exports = {
rules: {
'enforce-foo-bar': enforce_foo_bar_js_1.default,
'no-more-than-2-fields': no_more_than_2_fields_js_1.rule
},
configs: {
base: base_js_1.default,
recommended: recommended_js_1.default
}
};
91 changes: 91 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"name": "@salesforce/eslint-plugin-lwc-mobile",
"version": "0.0.1",
"description": "ESLint plugin for LWC mobility",
"contributors": [
{
"name": "Kevin Hawkins",
"url": "https://github.com/khawkins"
},
{
"name": "Meisam Seyed Aliroteh",
"url": "https://github.com/maliroteh-sf"
},
{
"name": "Takashi Arai",
"url": "https://github.com/sfdctaka"
},
{
"name": "Haifeng Li",
"url": "https://github.com/haifeng-li-at-salesforce"
},
{
"name": "Ben Zhang",
"url": "https://github.com/ben-zhang-li-at-salesforce"
}
],
"homepage": "https://github.com/salesforce/eslint-plugin-lwc-mobile",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/salesforce/eslint-plugin-lwc-mobile"
},
"scripts": {
"build": "tsc",
"format": "prettier --list-different \"**/*.{ts,js}\"",
"format:fix": "prettier --write \"**/*.{ts,js,json}\"",
"lint": "eslint src test",
"test": "jest --coverage"
},
"jestSonar": {
"sonar56x": true,
"reportPath": "reports/coverage",
"reportFile": "sonar-report.xml",
"indent": 4
},
"prettier": {
"printWidth": 100,
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "none"
},
"engines": {
"node": ">=18"
},
"type": "commonjs",
"main": "dist/src/index.js",
"files": [
"/dist"
],
"dependencies": {
"@graphql-eslint/eslint-plugin": "^3.20.1"
},
"devDependencies": {
"@eslint/js": "^9.2.0",
"@jest/globals": "^29.7.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@typescript-eslint/rule-tester": "^7.8.0",
"@typescript-eslint/utils": "^7.8.0",
"eslint": "^8.57.0",
"eslint-plugin-eslint-plugin": "^6.1.0",
"eslint-plugin-node": "^11.1.0",
"jest": "^29.7.0",
"jest-chain": "^1.1.6",
"jest-extended": "^4.0.1",
"jest-junit": "^16.0.0",
"jest-sonar-reporter": "^2.0.0",
"prettier": "^3.0.2",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0",
"@salesforce/eslint-plugin-lwc-mobile": "file:./dist"
},
"peerDependencies": {
"eslint": ">=7"
},
"volta": {
"node": "18.18.2"
}
}
4 changes: 4 additions & 0 deletions dist/rules/dummy/enforce-foo-bar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TSESLint } from '@typescript-eslint/utils';
type MessageIds = 'messageIdForFooMustBeBar';
declare const ruleEnforceFoorBar: TSESLint.RuleModule<MessageIds>;
export default ruleEnforceFoorBar;
46 changes: 46 additions & 0 deletions dist/rules/dummy/enforce-foo-bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const ruleEnforceFoorBar = {
defaultOptions: [],
meta: {
type: 'problem',
messages: {
messageIdForFooMustBeBar: 'Value other than "bar" assigned to `const foo`. Unexpected value: {{ notBar }}.'
},
fixable: 'code',
schema: []
},
create: (context) => ({
VariableDeclarator: (node) => {
var _a, _b;
// Performs action in the function on every variable declarator
if (node.parent.type === utils_1.AST_NODE_TYPES.VariableDeclaration) {
// Check if variable name is `foo`
if (node.id.type === utils_1.AST_NODE_TYPES.Identifier && node.id.name === 'foo') {
// Check if value of variable is "bar"
if (((_a = node.init) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Literal && ((_b = node.init) === null || _b === void 0 ? void 0 : _b.value) !== 'bar') {
/*
* Report error to ESLint. Error message uses
* a message placeholder to include the incorrect value
* in the error message.
* Also includes a `fix(fixer)` function that replaces
* any values assigned to `const foo` with "bar".
*/
context.report({
node,
messageId: 'messageIdForFooMustBeBar',
data: {
notBar: node.init.value
},
fix(fixer) {
return fixer.replaceText(node.init, '"bar"');
}
});
}
}
}
}
})
};
exports.default = ruleEnforceFoorBar;
2 changes: 2 additions & 0 deletions dist/rules/graphql/no-more-than-2-fields.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { GraphQLESLintRule } from '@graphql-eslint/eslint-plugin/';
export declare const rule: GraphQLESLintRule;
75 changes: 75 additions & 0 deletions dist/rules/graphql/no-more-than-2-fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rule = void 0;
const graphql_1 = require("graphql");
const RULE_ID = 'no-more-than-2-fields';
exports.rule = {
meta: {
type: 'suggestion',
hasSuggestions: true,
docs: {
description: 'Object should have no more than 2 fields.',
category: 'Operations',
recommended: true,
examples: [
{
title: 'Incorrect',
code: /* GraphQL */ `
query getSA($recoridId) {
uiapi {
query {
ServiceAppointment() {
edges {
node {
Id
Subject {
value
}
AccountId {
value
}
}
}
}
}
}
}
`
}
]
},
messages: {
[RULE_ID]: 'Field number should not exceed 2!'
},
schema: []
},
create(context) {
function checkNode(usedFields, node) {
const fieldName = node.value;
usedFields.add(fieldName);
if (usedFields.size === 3) {
context.report({
node,
messageId: RULE_ID
});
}
}
return {
SelectionSet(node) {
if (node.type === 'SelectionSet') {
const rawNode = node.rawNode();
// Traverse backwards to find 'node' from GraphQL ASTNode
const parentNode = node.parent.rawNode();
if (parentNode.kind === 'Field' && parentNode.name.value === 'node') {
const set = new Set();
for (const selection of rawNode.selections) {
if (selection.kind === graphql_1.Kind.FIELD) {
checkNode(set, selection.alias || selection.name);
}
}
}
}
}
};
}
};
4 changes: 4 additions & 0 deletions dist/src/configs/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const _default: {
plugins: string[];
};
export = _default;
4 changes: 4 additions & 0 deletions dist/src/configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
module.exports = {
plugins: ['@salesforce/lwc-mobile']
};
8 changes: 8 additions & 0 deletions dist/src/configs/recommended.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const _default: {
extends: string[];
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': "warn";
'@salesforce/lwc-mobile/no-more-than-2-fields': "warn";
};
};
export = _default;
8 changes: 8 additions & 0 deletions dist/src/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
module.exports = {
extends: ['./configs/base'],
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': 'warn',
'@salesforce/lwc-mobile/no-more-than-2-fields': 'warn'
}
};
19 changes: 19 additions & 0 deletions dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare const _default: {
rules: {
'enforce-foo-bar': import("@typescript-eslint/utils/ts-eslint").RuleModule<"messageIdForFooMustBeBar", [], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
'no-more-than-2-fields': import("@graphql-eslint/eslint-plugin").GraphQLESLintRule;
};
configs: {
base: {
plugins: string[];
};
recommended: {
extends: string[];
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': "warn";
'@salesforce/lwc-mobile/no-more-than-2-fields': "warn";
};
};
};
};
export = _default;
Loading

0 comments on commit 140ba21

Please sign in to comment.