@rpcbase/cli 0.67.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin.js CHANGED
@@ -9,9 +9,12 @@ const yargs = require("yargs/yargs")
9
9
  const {hideBin} = require("yargs/helpers")
10
10
 
11
11
  const increment_pkg = require("./src/versions/increment-pkg")
12
+ const lint = require("./src/lint")
13
+ const lint_staged = require("./src/lint-staged")
12
14
  const print_versions = require("./src/print_versions")
13
- const start_command = require("./src/start_command")
14
15
  const run_agent = require("./src/run_agent")
16
+ const start_command = require("./src/start_command")
17
+ const stylelint = require("./src/stylelint")
15
18
  const sync_dotenv = require("./src/sync-dotenv")
16
19
  const update = require("./src/update")
17
20
  const wait_for = require("./src/wait-for")
@@ -40,6 +43,15 @@ yargs(hideBin(process.argv))
40
43
  if (argv.version) return print_versions()
41
44
  start_command(argv)
42
45
  })
46
+ .command(["lint"], "Run eslint", (yargs) => {}, (argv) => {
47
+ lint(argv)
48
+ })
49
+ .command(["stylelint"], "Run stylelint", (yargs) => {}, (argv) => {
50
+ stylelint(argv)
51
+ })
52
+ .command(["lint-staged"], "Run lint-staged", (yargs) => {}, (argv) => {
53
+ lint_staged(argv)
54
+ })
43
55
  .command(["agent"], "Run the agent", (yargs) => {
44
56
  // yargs
45
57
  // .option("option1", {
@@ -0,0 +1,92 @@
1
+ /* @flow */
2
+ const mobile_overrides = require("./src/mobile_overrides")
3
+
4
+
5
+ module.exports = {
6
+ parser: "@babel/eslint-parser",
7
+ parserOptions: {
8
+ requireConfigFile: false,
9
+ },
10
+ // workingDirectories:{mode: "auto"},
11
+ ignorePatterns: [
12
+ "**/*.{css,scss}",
13
+ "*.eslintrc.js",
14
+ "**/node_modules/**",
15
+ "**/.nyc_output/**",
16
+ "**/coverage/**",
17
+ "**/build/**",
18
+ "client/static/**",
19
+ ],
20
+ env: {
21
+ browser: true,
22
+ es6: true,
23
+ node: true,
24
+ jest: true,
25
+ },
26
+ settings: {
27
+ react: {
28
+ version: "18"
29
+ }
30
+ },
31
+ plugins: ["react", "react-hooks", "flowtype", "import", "lodash"],
32
+ extends: [
33
+ "eslint:recommended",
34
+ "plugin:react/recommended",
35
+ "plugin:react/jsx-runtime",
36
+ "plugin:flowtype/recommended",
37
+ ],
38
+ globals: {
39
+ cx: "readonly",
40
+ monaco: "readonly",
41
+ // tests
42
+ page: "readonly",
43
+ browser: "readonly",
44
+ context: "readonly",
45
+ __DEV__: "readonly",
46
+ __DETOX__: "readonly",
47
+ },
48
+ rules: {
49
+ // "@rpcbase/lint/no-unused-imports": "warn",
50
+ "@rpcbase/lint/no-rb-restricted-imports": ["error", [
51
+ {"name": "mongodb", "message": "do not import the 'mongodb' module, this can cause issues, use mongoose.mongo"},
52
+ {"name": "mongoose", "message": "use @rpcbase/server/mongoose"},
53
+ ]],
54
+ "array-callback-return": "error",
55
+ "comma-dangle": ["error", "always-multiline"],
56
+ "import/newline-after-import": ["error", {"count": 2}],
57
+ "import/extensions": ["error", "never", {"svg": "always", "scss": "always", "css": "always", "json": "always"}],
58
+ "import/no-relative-parent-imports": ["warn"],
59
+ "lodash/import-scope": ["error", "method"],
60
+ "max-len": "off",
61
+ "no-async-promise-executor": "warn",
62
+ "no-case-declarations": "warn",
63
+ "no-console": ["warn", {allow: ["warn", "error"]}],
64
+ "no-constant-condition": ["warn", {"checkLoops": false}],
65
+ "no-empty": ["error", { "allowEmptyCatch": true }],
66
+ "no-irregular-whitespace": ["error", {skipRegExps: false, skipStrings: false, skipComments: false}],
67
+ "no-misleading-character-class": ["error"],
68
+ "no-return-await": "error",
69
+ "no-shadow": ["error", {"allow": ["err", "error"]}],
70
+ "no-redeclare": ["error", {"builtinGlobals": true}],
71
+ "no-undefined": "warn",
72
+ "no-useless-escape": "warn",
73
+ "no-use-before-define": ["error", {variables: true, functions: true, classes: true}],
74
+ "no-var": "error",
75
+ "flowtype/boolean-style": ["error", "boolean"],
76
+ "prefer-template": ["error"],
77
+ "quotes": ["error", "double", {"allowTemplateLiterals": true}],
78
+ "react-hooks/exhaustive-deps": "warn",
79
+ "react-hooks/rules-of-hooks": "error",
80
+ "react/display-name": "warn",
81
+ "react/no-access-state-in-setstate": "error",
82
+ "react/no-find-dom-node": "warn",
83
+ "react/no-unescaped-entities": "warn",
84
+ "react/no-unknown-property": "warn",
85
+ "react/react-in-jsx-scope": "off",
86
+ "spaced-comment": ["error", "always"],
87
+ "space-before-function-paren": ["error", "never"],
88
+ },
89
+ overrides: [
90
+ mobile_overrides,
91
+ ]
92
+ }
@@ -0,0 +1,8 @@
1
+ /* @flow */
2
+
3
+ module.exports = {
4
+ rules: {
5
+ "no-unused-imports": require("./src/rules/no-unused-imports"),
6
+ "no-rb-restricted-imports": require("./src/rules/no-rb-restricted-imports")
7
+ }
8
+ }
@@ -0,0 +1,10 @@
1
+ /* @flow */
2
+
3
+ module.exports = {
4
+ files: [ "mobile/spec/**" ],
5
+ globals: {
6
+ device: "readonly",
7
+ element: "readonly",
8
+ by: "readonly",
9
+ },
10
+ }
@@ -0,0 +1,31 @@
1
+ /* @flow */
2
+
3
+ module.exports = {
4
+ create(context) {
5
+ const restrictedImports = context.options[0] || []
6
+
7
+ function checkNode(node, moduleName) {
8
+ const restrictedImport = restrictedImports.find(r => r.name === moduleName)
9
+ if (restrictedImport) {
10
+ context.report({
11
+ node,
12
+ message: restrictedImport.message,
13
+ data: {
14
+ name: moduleName,
15
+ },
16
+ })
17
+ }
18
+ }
19
+
20
+ return {
21
+ "ImportDeclaration"(node) {
22
+ checkNode(node, node.source.value)
23
+ },
24
+ "CallExpression"(node) {
25
+ if (node.callee.name === "require" && node.arguments[0] && node.arguments[0].type === "Literal") {
26
+ checkNode(node, node.arguments[0].value)
27
+ }
28
+ },
29
+ }
30
+ },
31
+ }
@@ -0,0 +1,67 @@
1
+ /* @flow */
2
+
3
+ const noUnusedImports = {
4
+ meta: {
5
+ fixable: "code",
6
+ },
7
+ create(context) {
8
+ const getRemovalRange = (importSpecifier, sourceCode) => {
9
+
10
+ const tokenBefore = sourceCode.getTokenBefore(importSpecifier)
11
+ const tokenAfter = sourceCode.getTokenAfter(importSpecifier)
12
+
13
+ // if there is a comma before the punctuator, remove the comma as well
14
+ if (tokenBefore.value === "{") {
15
+ const tokenBeforeBefore = sourceCode.getTokenBefore(tokenBefore)
16
+ if (tokenBeforeBefore.value === ",") {
17
+ return [
18
+ sourceCode.getTokenBefore(tokenBeforeBefore).range[1],
19
+ tokenAfter.range[1],
20
+ ]
21
+ }
22
+ }
23
+
24
+ if (tokenBefore.value === ",") {
25
+ return [tokenBefore.range[0], importSpecifier.range[1]]
26
+ } else if (tokenAfter.value === ",") {
27
+ return [importSpecifier.range[0] - 1, tokenAfter.range[1]] // Include the space before the specifier
28
+ }
29
+
30
+ // When there is no comma, remove the whole specifier including surrounding spaces
31
+ return [
32
+ sourceCode.getTokenBefore(tokenBefore).range[1],
33
+ sourceCode.getTokenAfter(tokenAfter).range[0],
34
+ ]
35
+ }
36
+
37
+ return {
38
+ "ImportDeclaration"(node) {
39
+ const sourceCode = context.getSourceCode()
40
+ const importSpecifiers = node.specifiers
41
+
42
+ importSpecifiers.forEach((importSpecifier) => {
43
+ const localName = importSpecifier.local.name
44
+
45
+ const variable = context.getScope().variables.find((v) => v.name === localName)
46
+
47
+ if (variable && variable.references.length === 0) {
48
+ context.report({
49
+ node: importSpecifier,
50
+ message: `'${localName}' is defined but never used.`,
51
+ fix(fixer) {
52
+ if (importSpecifiers.length === 1) {
53
+ return fixer.remove(node)
54
+ } else {
55
+ const removalRange = getRemovalRange(importSpecifier, sourceCode)
56
+ return fixer.removeRange(removalRange)
57
+ }
58
+ },
59
+ })
60
+ }
61
+ })
62
+ },
63
+ }
64
+ },
65
+ }
66
+
67
+ module.exports = noUnusedImports
@@ -0,0 +1,54 @@
1
+ /* @flow */
2
+ const { RuleTester } = require("eslint")
3
+
4
+ const noUnusedImports = require("./index")
5
+
6
+ const ruleTester = new RuleTester({
7
+ parserOptions: {
8
+ ecmaVersion: 2021,
9
+ sourceType: "module",
10
+ },
11
+ });
12
+
13
+
14
+ ruleTester.run('no-unused-imports', noUnusedImports, {
15
+ valid: [
16
+ "import used from './module'; used();",
17
+ "import * as used from './module'; used.foo();",
18
+ "import { used } from './module'; used();",
19
+ "import { used as alias } from './module'; alias();",
20
+ ],
21
+
22
+ invalid: [
23
+ {
24
+ code: "import unused from './module';",
25
+ errors: [{ message: "'unused' is defined but never used." }],
26
+ output: '',
27
+ },
28
+ {
29
+ code: "import * as unused from './module';",
30
+ errors: [{ message: "'unused' is defined but never used." }],
31
+ output: '',
32
+ },
33
+ {
34
+ code: "import { unused } from './module';",
35
+ errors: [{ message: "'unused' is defined but never used." }],
36
+ output: '',
37
+ },
38
+ {
39
+ code: "import { unused as alias } from './module';",
40
+ errors: [{ message: "'alias' is defined but never used." }],
41
+ output: '',
42
+ },
43
+ {
44
+ code: "import used, { unused } from './module'; used();",
45
+ errors: [{ message: "'unused' is defined but never used." }],
46
+ output: "import used from './module'; used();",
47
+ },
48
+ {
49
+ code: "import { used, unused } from './module'; used();",
50
+ errors: [{ message: "'unused' is defined but never used." }],
51
+ output: "import { used } from './module'; used();",
52
+ },
53
+ ],
54
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/cli",
3
- "version": "0.67.0",
3
+ "version": "0.68.0",
4
4
  "license": "SSPL-1.0",
5
5
  "bin": {
6
6
  "rb": "./bin.js"
@@ -10,6 +10,8 @@
10
10
  },
11
11
  "files": [
12
12
  "src/",
13
+ "eslint/",
14
+ "stylelint/",
13
15
  "!src/**/*.test.js"
14
16
  ],
15
17
  "scripts": {
@@ -38,16 +40,30 @@
38
40
  }
39
41
  },
40
42
  "dependencies": {
43
+ "@babel/core": "7.24.9",
44
+ "@babel/eslint-parser": "7.25.0",
45
+ "@babel/plugin-syntax-flow": "7.24.7",
46
+ "@babel/plugin-transform-react-jsx": "7.24.7",
41
47
  "@rpcbase/agent": "0.42.0",
42
48
  "bluebird": "3.7.2",
43
49
  "concurrently": "8.2.2",
44
- "debug": "4.3.4",
50
+ "debug": "4.3.6",
45
51
  "dotenv": "16.4.5",
52
+ "eslint": "8.57.0",
53
+ "eslint-plugin-flowtype": "8.0.3",
54
+ "eslint-plugin-import": "2.29.1",
55
+ "eslint-plugin-lodash": "8.0.0",
56
+ "eslint-plugin-react": "7.35.0",
57
+ "eslint-plugin-react-hooks": "4.6.2",
58
+ "lint-staged": "15.2.7",
46
59
  "octokit": "3.1.2",
47
60
  "parse-dotenv": "2.1.0",
48
- "picocolors": "1.0.0",
61
+ "picocolors": "1.0.1",
49
62
  "semver": "7.6.0",
50
- "validator": "13.11.0",
63
+ "stylelint": "16.7.0",
64
+ "stylelint-config-standard": "36.0.0",
65
+ "stylelint-config-standard-scss": "13.1.0",
66
+ "validator": "13.12.0",
51
67
  "yargs": "17.7.2"
52
68
  },
53
69
  "devDependencies": {
@@ -0,0 +1,17 @@
1
+ const path = require("path")
2
+ const {spawn} = require("child_process")
3
+
4
+ const {hideBin} = require("yargs/helpers")
5
+
6
+ module.exports = () => {
7
+ const args = hideBin(process.argv).slice(1) // remove first arg
8
+
9
+ const package_dir = path.dirname(require.resolve("lint-staged/package.json"))
10
+ const bin_path = path.join(package_dir, "./bin/lint-staged.js")
11
+
12
+ const ps = spawn(bin_path, args, { stdio: "inherit" })
13
+
14
+ ps.on("close", (code) => {
15
+ process.exit(code)
16
+ })
17
+ }
package/src/lint.js ADDED
@@ -0,0 +1,17 @@
1
+ const path = require("path")
2
+ const {spawn} = require("child_process")
3
+
4
+ const {hideBin} = require("yargs/helpers")
5
+
6
+ module.exports = () => {
7
+ const args = hideBin(process.argv).slice(1) //remove first arg (our rb command 'lint')
8
+
9
+ const eslint_path = path.dirname(require.resolve("eslint/package.json"))
10
+ const bin_path = path.join(eslint_path, "./bin/eslint.js")
11
+
12
+ const ps = spawn(bin_path, args, { stdio: "inherit" })
13
+
14
+ ps.on("close", (code) => {
15
+ process.exit(code)
16
+ })
17
+ }
@@ -0,0 +1,25 @@
1
+ const path = require("path")
2
+ const fs = require("fs")
3
+ const {spawn} = require("child_process")
4
+
5
+ const {hideBin} = require("yargs/helpers")
6
+
7
+ module.exports = () => {
8
+ const args = hideBin(process.argv).slice(1) //remove first arg
9
+
10
+ const config_path = path.join(process.cwd(), "./.stylelintrc.js")
11
+ const has_config = fs.existsSync(config_path)
12
+
13
+ if (!has_config) {
14
+ throw new Error("cannot find .stylelintrc.js config file")
15
+ }
16
+
17
+ const stylelint_path = path.dirname(require.resolve("stylelint/package.json"))
18
+ const bin_path = path.join(stylelint_path, "./bin/stylelint.mjs")
19
+
20
+ const ps = spawn(bin_path, ["--config", config_path, ...args], { stdio: "inherit" })
21
+
22
+ ps.on("close", (code) => {
23
+ process.exit(code)
24
+ })
25
+ }
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ "extends": [
3
+ "stylelint-config-standard-scss"
4
+ ],
5
+ "rules": {
6
+ "color-named": ["never", {severity: "warning"}],
7
+ "color-no-hex": [true, {severity: "warning"}],
8
+ "declaration-block-no-redundant-longhand-properties": null,
9
+ "declaration-empty-line-before": null,
10
+ "no-descending-specificity": [true, {severity: "warning"}],
11
+ "scss/comment-no-empty": null,
12
+ "scss/no-global-function-names": [true, {severity: "warning"}],
13
+ "selector-class-pattern": null,
14
+ }
15
+ }