From 260aa8c4199e3ffb23a095c9c33ac6bcf6c1fcf8 Mon Sep 17 00:00:00 2001 From: Nicolas Blanc Date: Mon, 7 Apr 2025 14:49:03 +0200 Subject: [PATCH] Repair rubocop refusing to run (#97) - Upgrade dependencies - Use ESlint instead of TSLint(obsolete) - Remove a null token parameter in findFiles call, generating extension load error - Replace rootPath (deprecated) by workspaceFolders[0].uri.fsPath - Correct a language/snippet file loading problem(berkshelf vs berkfile) (#142) - Correct gif image url in README (master branch now is main) - Escape $ in some snippet description to avoid warning from VSCode Signed-off-by: Nicolas Blanc --- .github/dependabot.yml | 8 ------ .github/workflows/ci.yml | 2 +- README.md | 2 +- extension.ts | 10 +++---- package.json | 22 +++++++--------- snippets/chef_inspec_resources.json | 26 +++++++++---------- ...elf.cson.json => chef_berksfile.cson.json} | 0 7 files changed, 29 insertions(+), 41 deletions(-) rename syntaxes/{chef_berkshelf.cson.json => chef_berksfile.cson.json} (100%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b52da40..54726f6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,11 +7,3 @@ updates: time: "06:00" timezone: America/Los_Angeles open-pull-requests-limit: 10 - ignore: - - dependency-name: "@types/node" - versions: - - 15.0.0 - - dependency-name: typescript - versions: - - 4.1.4 - - 4.2.2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01ee7e5..12d7a6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ runs-on: ubuntu-latest strategy: matrix: - node-version: [15.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@main - name: Use Node.js ${{ matrix.node-version }} diff --git a/README.md b/README.md index d5e7952..ed849b3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The Progress Chef Infra Extension for Visual Studio Code offers rich language support for Chef Infra and Chef InSpec when using [Visual Studio Code](http://code.visualstudio.com). -![install and demo](https://github.com/chef/vscode-chef/raw/master/images/vscode-chef-install.gif) +![install and demo](https://github.com/chef/vscode-chef/blob/main/images/vscode-chef-install.gif) ## Features diff --git a/extension.ts b/extension.ts index 94a823f..56aeb7f 100644 --- a/extension.ts +++ b/extension.ts @@ -74,7 +74,7 @@ function updateRubyFileCountAndValidate(warn: boolean = false): void { uri_array.forEach(uriCounter) validate(warn); } - vscode.workspace.findFiles("**/*.rb", null, stopAt, null) + vscode.workspace.findFiles("**/*.rb", null, stopAt) .then(countAndValidate) } @@ -104,7 +104,7 @@ function validateOpenFiles(): void { } function validateEntireWorkspace(): void { - validatePaths([vscode.workspace.rootPath]) + validatePaths([vscode.workspace.workspaceFolders[0].uri.fsPath]) } function validatePaths(paths: Array): void { @@ -112,16 +112,16 @@ function validatePaths(paths: Array): void { let spawn = require("child_process").spawnSync; let rubocop: any; if (rubocopConfigFile) { - rubocop = spawn(rubocopPath, ["--parallel", "--config", rubocopConfigFile, "-f", "j"].concat(paths), { cwd: vscode.workspace.rootPath }); + rubocop = spawn(rubocopPath, ["--parallel", "--config", rubocopConfigFile, "-f", "j"].concat(paths), { shell: true, cwd: vscode.workspace.workspaceFolders[0].uri.fsPath }); } else { - rubocop = spawn(rubocopPath, ["--parallel", "-f", "j"].concat(paths), { cwd: vscode.workspace.rootPath }); + rubocop = spawn(rubocopPath, ["--parallel", "-f", "j"].concat(paths), { shell: true, cwd: vscode.workspace.workspaceFolders[0].uri.fsPath }); } let rubocopOutput = JSON.parse(rubocop.stdout); if (rubocop.status < 2) { let arr = []; for (var r = 0; r < rubocopOutput.files.length; r++) { var rubocopFile = rubocopOutput.files[r]; - let uri: vscode.Uri = vscode.Uri.file((path.join(vscode.workspace.rootPath, rubocopFile.path))); + let uri: vscode.Uri = vscode.Uri.file((path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, rubocopFile.path))); var offenses = rubocopFile.offenses; let diagnostics: vscode.Diagnostic[] = []; for (var i = 0; i < offenses.length; i++) { diff --git a/package.json b/package.json index a54154b..300ebe8 100644 --- a/package.json +++ b/package.json @@ -26,22 +26,18 @@ "language" ], "activationEvents": [ - "onLanguage:chef_berkshelf", - "onLanguage:chef_inspec", - "onLanguage:chef_metadata", - "onLanguage:chef_policyfile", - "onLanguage:chef_recipe_yaml", "workspaceContains:**/metadata.rb" ], "main": "./out/extension", "devDependencies": { - "@types/node": "^20.8.5", + "@types/node": "^22.14.0", "@types/vscode": "^1.83.0", + "@vscode/test-electron": "^2.4.1", + "@vscode/vsce": "^3.3.2", + "eslint": "9.23.0", "path": "0.12.7", - "tslint": "6.1.3", - "typescript": "5.2.2", - "@vscode/vsce": "^2.21.1", - "@vscode/test-electron": "^2.3.5" + "typescript": "5.8.2", + "typescript-eslint": "^8.29.0" }, "extensionDependencies": [ "Shopify.ruby-lsp", @@ -133,9 +129,9 @@ "path": "./syntaxes/chef_inspec.cson.json" }, { - "language": "chef_berkshelf", - "scopeName": "source.chef.berkshelf", - "path": "./syntaxes/chef_berkshelf.cson.json" + "language": "chef_berksfile", + "scopeName": "source.chef.chef_berksfile", + "path": "./syntaxes/chef_berksfile.cson.json" }, { "language": "chef_policyfile", diff --git a/snippets/chef_inspec_resources.json b/snippets/chef_inspec_resources.json index eb94eba..d17b346 100644 --- a/snippets/chef_inspec_resources.json +++ b/snippets/chef_inspec_resources.json @@ -397,7 +397,7 @@ }, "aws_lambda": { "prefix": "aws_lambda", - "body": "describe aws_lambda do\n it { should exist}\n its ('handler') { should eq 'main.on_event'}\n its ('version') { should eq '$LATEST' }\n its ('runtime') { should eq 'python3.7' }\nend", + "body": "describe aws_lambda do\n it { should exist}\n its ('handler') { should eq 'main.on_event'}\n its ('version') { should eq '\\$LATEST' }\n its ('runtime') { should eq 'python3.7' }\nend", "description": "Use the `aws_lambda` resource to test a specific lambda.", "scope": "source.ruby.chef_inspec" }, @@ -1010,7 +1010,7 @@ "cassandradb_conf": { "prefix": "cassandradb_conf", "body": "describe cassandradb_conf do\n\tits('config item') { should eq 'value' }\nend", - "description": "Use the `cassandradb_conf` Chef InSpec audit resource to test the configuration of a Cassandra database, which is typically located at `$CASSANDRA_HOME/cassandra.yaml` or `$CASSANDRA_HOME\\conf\\cassandra.yaml` depending upon the platform.", + "description": "Use the `cassandradb_conf` Chef InSpec audit resource to test the configuration of a Cassandra database, which is typically located at `\\$CASSANDRA_HOME/cassandra.yaml` or `\\$CASSANDRA_HOME\\conf\\cassandra.yaml` depending upon the platform.", "scope": "source.ruby.chef_inspec" }, "cassandradb_session": { @@ -1255,7 +1255,7 @@ }, "google_cloudfunctions_cloud_function": { "prefix": "google_cloudfunctions_cloud_function", - "body": "describe google_cloudfunctions_cloud_function(project: 'chef-gcp-inspec', location: 'europe-west1', name: 'inspec-gcp-function') do\n it { should exist }\n its('description') { should eq 'A description of the function' }\n its('available_memory_mb') { should eq '128' }\n its('https_trigger.url') { should match /\\/inspec-gcp-function$/ }\n its('entry_point') { should eq 'hello' }\n its('environment_variables') { should include('MY_ENV_VAR' => 'val1') }\nend", + "body": "describe google_cloudfunctions_cloud_function(project: 'chef-gcp-inspec', location: 'europe-west1', name: 'inspec-gcp-function') do\n it { should exist }\n its('description') { should eq 'A description of the function' }\n its('available_memory_mb') { should eq '128' }\n its('https_trigger.url') { should match /\\/inspec-gcp-function\\$/ }\n its('entry_point') { should eq 'hello' }\n its('environment_variables') { should include('MY_ENV_VAR' => 'val1') }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -1279,7 +1279,7 @@ }, "google_compute_autoscaler": { "prefix": "google_compute_autoscaler", - "body": "describe google_compute_autoscaler(project: 'chef-gcp-inspec', zone: 'zone', name: 'inspec-gcp-autoscaler') do\n it { should exist }\n\n its('target') { should match /\\/inspec-gcp-igm$/ }\n its('autoscaling_policy.max_num_replicas') { should eq '5' }\n its('autoscaling_policy.min_num_replicas') { should eq '1' }\n its('autoscaling_policy.cool_down_period_sec') { should eq '60' }\n its('autoscaling_policy.cpu_utilization.utilization_target') { should eq '0.5' }\nend", + "body": "describe google_compute_autoscaler(project: 'chef-gcp-inspec', zone: 'zone', name: 'inspec-gcp-autoscaler') do\n it { should exist }\n\n its('target') { should match /\\/inspec-gcp-igm\\$/ }\n its('autoscaling_policy.max_num_replicas') { should eq '5' }\n its('autoscaling_policy.min_num_replicas') { should eq '1' }\n its('autoscaling_policy.cool_down_period_sec') { should eq '60' }\n its('autoscaling_policy.cpu_utilization.utilization_target') { should eq '0.5' }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -1363,7 +1363,7 @@ }, "google_compute_global_forwarding_rule": { "prefix": "google_compute_global_forwarding_rule", - "body": "describe google_compute_global_forwarding_rule(project: 'chef-gcp-inspec', name: 'inspec-gcp-global-forwarding-rule') do\n it { should exist }\n its('port_range') { should eq '80-80' }\n its('target') { should match /\\/inspec-gcp-http-proxy$/ }\nend", + "body": "describe google_compute_global_forwarding_rule(project: 'chef-gcp-inspec', name: 'inspec-gcp-global-forwarding-rule') do\n it { should exist }\n its('port_range') { should eq '80-80' }\n its('target') { should match /\\/inspec-gcp-http-proxy\\$/ }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -1561,13 +1561,13 @@ }, "google_compute_route": { "prefix": "google_compute_route", - "body": "describe google_compute_route(project: 'chef-gcp-inspec', name: 'inspec-gcp-route') do\n it { should exist }\n its('dest_range') { should eq '15.0.0.0/24' }\n its('network') { should match /\\/gcp-inspec-network$/ }\n its('next_hop_ip') { should eq '10.2.0.1' }\n its('priority') { should eq '100' }\nend", + "body": "describe google_compute_route(project: 'chef-gcp-inspec', name: 'inspec-gcp-route') do\n it { should exist }\n its('dest_range') { should eq '15.0.0.0/24' }\n its('network') { should match /\\/gcp-inspec-network\\$/ }\n its('next_hop_ip') { should eq '10.2.0.1' }\n its('priority') { should eq '100' }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, "google_compute_router": { "prefix": "google_compute_router", - "body": "describe google_compute_router(project: 'chef-gcp-inspec', region: 'europe-west2', name: 'inspec-gcp-router') do\n it { should exist }\n its('bgp.asn') { should eq '64514' }\n its('bgp.advertise_mode') { should eq 'CUSTOM' }\n its('bgp.advertised_groups') { should include 'ALL_SUBNETS' }\n its('bgp.advertised_ip_ranges.count') { should eq 2 }\n its('bgp.advertised_ip_ranges.first.range') { should eq '1.2.3.4' }\n its('bgp.advertised_ip_ranges.last.range') { should eq '1.2.3.4' }\n its('network') { should match /\\/gcp-inspec-network$/ }\n end", + "body": "describe google_compute_router(project: 'chef-gcp-inspec', region: 'europe-west2', name: 'inspec-gcp-router') do\n it { should exist }\n its('bgp.asn') { should eq '64514' }\n its('bgp.advertise_mode') { should eq 'CUSTOM' }\n its('bgp.advertised_groups') { should include 'ALL_SUBNETS' }\n its('bgp.advertised_ip_ranges.count') { should eq 2 }\n its('bgp.advertised_ip_ranges.first.range') { should eq '1.2.3.4' }\n its('bgp.advertised_ip_ranges.last.range') { should eq '1.2.3.4' }\n its('network') { should match /\\/gcp-inspec-network\\$/ }\n end", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -1675,7 +1675,7 @@ }, "google_compute_target_http_proxy": { "prefix": "google_compute_target_http_proxy", - "body": "describe google_compute_target_http_proxy(project: 'chef-gcp-inspec', name: 'inspec-gcp-http-proxy') do\n it { should exist }\n its('description') { should eq 'A HTTP proxy' }\n its('url_map') { should match /\\/inspec-gcp-url-map$/ }\nend", + "body": "describe google_compute_target_http_proxy(project: 'chef-gcp-inspec', name: 'inspec-gcp-http-proxy') do\n it { should exist }\n its('description') { should eq 'A HTTP proxy' }\n its('url_map') { should match /\\/inspec-gcp-url-map\\$/ }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -1687,7 +1687,7 @@ }, "google_compute_target_https_proxy": { "prefix": "google_compute_target_https_proxy", - "body": "describe google_compute_target_https_proxy(project: 'chef-gcp-inspec', name: 'inspec-gcp-https-proxy') do\n it { should exist }\n its('url_map') { should match /\\/inspec-gcp-url-map$/ }\n its('description') { should eq 'A HTTPS target proxy' }\nend", + "body": "describe google_compute_target_https_proxy(project: 'chef-gcp-inspec', name: 'inspec-gcp-https-proxy') do\n it { should exist }\n its('url_map') { should match /\\/inspec-gcp-url-map\\$/ }\n its('description') { should eq 'A HTTPS target proxy' }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -1711,13 +1711,13 @@ }, "google_compute_target_tcp_proxy": { "prefix": "google_compute_target_tcp_proxy", - "body": "describe google_compute_target_tcp_proxy(project: 'chef-gcp-inspec', name: 'inspec-gcp-target-tcp-proxy') do\n it { should exist }\n its('proxy_header') { should eq 'NONE' }\n its('service') { should match /\\/gcp-inspec-tcp-backend-service$/ }\nend", + "body": "describe google_compute_target_tcp_proxy(project: 'chef-gcp-inspec', name: 'inspec-gcp-target-tcp-proxy') do\n it { should exist }\n its('proxy_header') { should eq 'NONE' }\n its('service') { should match /\\/gcp-inspec-tcp-backend-service\\$/ }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, "google_compute_url_map": { "prefix": "google_compute_url_map", - "body": "describe google_compute_url_map(project: 'chef-gcp-inspec', name: 'inspec-gcp-url-map') do\n it { should exist }\n its('description') { should eq 'URL map description' }\n its('default_service') { should match /\\/inspec-gcp-backend-service$/ }\n its('host_rules.count') { should eq 1 }\n its('host_rules.first.hosts') { should include 'site.com' }\n its('path_matchers.count') { should eq 1 }\n its('path_matchers.first.default_service') { should match /\\/inspec-gcp-backend-service$/ }\n its('tests.count') { should eq 1 }\n its('tests.first.host') { should eq 'test.com' }\n its('tests.first.path') { should eq '/home' }\nend", + "body": "describe google_compute_url_map(project: 'chef-gcp-inspec', name: 'inspec-gcp-url-map') do\n it { should exist }\n its('description') { should eq 'URL map description' }\n its('default_service') { should match /\\/inspec-gcp-backend-service\\$/ }\n its('host_rules.count') { should eq 1 }\n its('host_rules.first.hosts') { should include 'site.com' }\n its('path_matchers.count') { should eq 1 }\n its('path_matchers.first.default_service') { should match /\\/inspec-gcp-backend-service\\$/ }\n its('tests.count') { should eq 1 }\n its('tests.first.host') { should eq 'test.com' }\n its('tests.first.path') { should eq '/home' }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -2311,7 +2311,7 @@ }, "google_sourcerepo_repositories": { "prefix": "google_sourcerepo_repositories", - "body": "describe.one do\n google_sourcerepo_repositories(project: 'chef-gcp-inspec').names.each do |name|\n describe name do\n\tit { should match /\\/repos\\/#{repo_name}$/ }\nend", + "body": "describe.one do\n google_sourcerepo_repositories(project: 'chef-gcp-inspec').names.each do |name|\n describe name do\n\tit { should match /\\/repos\\/#{repo_name}\\$/ }\nend", "description": null, "scope": "source.ruby.chef_inspec" }, @@ -2708,7 +2708,7 @@ "oracledb_listener_conf": { "prefix": "oracledb_listener_conf", "body": "describe oracledb_listener_conf do\n\tits('config item') { should eq 'value' }\nend", - "description": "Use the `oracledb_listener_conf` Chef InSpec audit resource to test the listeners settings of Oracle DB, typically located at `$ORACLE_HOME/network/admin/listener.ora` or `$ORACLE_HOME\\network\\admin\\listener.ora` depending upon the platform.", + "description": "Use the `oracledb_listener_conf` Chef InSpec audit resource to test the listeners settings of Oracle DB, typically located at `\\$ORACLE_HOME/network/admin/listener.ora` or `\\$ORACLE_HOME\\network\\admin\\listener.ora` depending upon the platform.", "scope": "source.ruby.chef_inspec" }, "oracledb_session": { diff --git a/syntaxes/chef_berkshelf.cson.json b/syntaxes/chef_berksfile.cson.json similarity index 100% rename from syntaxes/chef_berkshelf.cson.json rename to syntaxes/chef_berksfile.cson.json