Skip to content

Commit

Permalink
JS-225 Release eslint-plugin-sonarjs (#4752)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez authored Jul 15, 2024
1 parent 8480767 commit 3f97c77
Show file tree
Hide file tree
Showing 588 changed files with 8,369 additions and 2,322 deletions.
26 changes: 26 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ win_vm_definition: &WINDOWS_VM_DEFINITION
npmrc_script_definition: &NPMRC_SCRIPT_DEFINITION
npmrc_script:
- cp .cirrus/npmrc $CIRRUS_WORKING_DIR/.npmrc
- cp .cirrus/npmrc $CIRRUS_WORKING_DIR/packages/jsts/src/rules/.npmrc
- cp .cirrus/npmrc $CIRRUS_WORKING_DIR/its/eslint-plugin-sonarjs/.npmrc

win_ssd_and_clone:
&WIN_SSD_AND_CLONE # copy&paste from https://github.com/SonarSource/sonar-cpp/blob/a8c6f1e45a12393508682a013ac7ee35eb92bece/.cirrus.yml#L45
Expand Down Expand Up @@ -284,6 +286,30 @@ js_ts_ruling_task:
- npm run ruling -- --maxWorkers=8
cleanup_before_cache_script: cleanup_maven_repository

eslint_plugin_test_task:
eks_container:
<<: *CONTAINER_DEFINITION
dockerfile: .cirrus/nodejs.Dockerfile
docker_arguments:
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
NODE_VERSION: 20
env:
CIRRUS_CLONE_DEPTH: 1
SONARSOURCE_QA: true
<<: *MAVEN_CACHE
<<: *NPMRC_SCRIPT_DEFINITION
# needed because we need to build the plugin
<<: *RUNTIME_CACHE
eslint_its_script:
- . ~/.profile
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd packages/jsts/src/rules
- npm run build
- cd ../../../../its/eslint-plugin-sonarjs
- npm run build
- npm run test

css_ruling_task:
depends_on:
- build
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/release_eslint_plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Release eslint-plugin-sonarjs

# Workflow runs when manually triggered using the UI or API.
on:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
release_version:
description: 'Version (semver)'
required: true

jobs:
publish:
permissions:
id-token: write # required for SonarSource/vault-action-wrapper
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event.inputs.release_version }}
NPM_REPOSITORY: "sonarsource-npm-public"
SCOPE: ""
PACKAGE: "eslint-plugin-sonarjs"
steps:
- name: Vault
id: secrets
uses: SonarSource/vault-action-wrapper@d1c1ab4ca5ad07fd9cdfe1eff038a39673dfca64 # tag=2.4.2-1
with:
secrets:
development/kv/data/repox url | repox_url;
development/artifactory/token/SonarSource-eslint-plugin-sonarjs-qa-deployer access_token | qa_deployer_access_token;
development/artifactory/token/SonarSource-eslint-plugin-sonarjs-promoter access_token | promoter_access_token;
development/kv/data/npmjs sonartech_npm_token | npm_token;
- name: Setup JFrog for deploy
uses: SonarSource/jfrog-setup-wrapper@eb712d76540e5d1f3756303f30387657fb204e52 # tag=2.4.1-1
with:
jfrogAccessToken: ${{ fromJSON(steps.secrets.outputs.vault).qa_deployer_access_token }}
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 18
- run: mv .github/workflows/.npmrc .npmrc
- run: mv .github/workflows/.npmrc packages/jsts/src/rules/.npmrc
- name: Publish npm package
env:
NPM_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).npm_token }}
run: |
jfrog rt npm-config --repo-resolve npm --repo-deploy sonarsource-npm-public-qa
jfrog rt npm-ci
cd packages/jsts/src/rules/
npm run build
cd lib/
npm publish
jfrog rt npm-publish --build-name=eslint-plugin-sonarjs --build-number=${{ github.event.inputs.release_version }}
jfrog rt build-publish eslint-plugin-sonarjs ${{ github.event.inputs.release_version }}
- name: Promote npm package
env:
PROMOTER_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).promoter_access_token }}
REPOX_URL: ${{ fromJSON(steps.secrets.outputs.vault).repox_url }}
run: |
jfrog rt bpr --access-token $PROMOTER_TOKEN --url $REPOX_URL --status it-passed eslint-plugin-sonarjs ${{ github.event.inputs.release_version }} sonarsource-npm-public-builds
jfrog rt bpr --access-token $PROMOTER_TOKEN --url $REPOX_URL --status released eslint-plugin-sonarjs ${{ github.event.inputs.release_version }} sonarsource-npm-public-releases
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ Desktop.ini
# ---- Sonar
.sonar
.scannerwork

# eslint-plugin-sonarjs
eslint-plugin-sonarjs-*.tgz
12 changes: 12 additions & 0 deletions its/eslint-plugin-sonarjs/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const plugin = require('eslint-plugin-sonarjs');

console.log(`Loaded ${Object.keys(plugin.configs.recommended.rules).length} rules`);

module.exports = [
{
files: ['./*.js'],
languageOptions: { sourceType: 'commonjs' },
},
plugin.configs.recommended,
{ rules: { 'sonarjs/accessor-pairs': 'error' } },
];
12 changes: 12 additions & 0 deletions its/eslint-plugin-sonarjs/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import plugin from 'eslint-plugin-sonarjs';

console.log(`Loaded ${Object.keys(plugin.configs.recommended.rules).length} rules`);

export default [
{
files: ['./*.js'],
languageOptions: { sourceType: 'commonjs' },
},
plugin.configs.recommended,
{ rules: { 'sonarjs/accessor-pairs': 'error' } },
];
43 changes: 43 additions & 0 deletions its/eslint-plugin-sonarjs/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function S3776(foo) {
if (foo.bar) {
if (foo.baz) {
if (foo.qux) {
if (foo.fred) {
if (foo.thud) {
if (foo.abc) {
foo.bcd();
}
}
}
}
}
}
}

function S2703(foo) {
if (x == 0) {
x = 42;
}
}

function S2376() {
class C {
set m(a) {
this.a = a;
}
}
}

/*
function S125() {
class C {
set m(a) {
this.a = a;
}
}
}
*/

// if (something) {}
23 changes: 23 additions & 0 deletions its/eslint-plugin-sonarjs/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { test } = require('node:test');
const assert = require('node:assert');
const spawn = require('cross-spawn');

test('should work with CommonJS config', async t => {
const result = spawn.sync('npx', ['eslint', '-c', 'eslint.config.cjs', 'file.js'], {
cwd: __dirname,
encoding: 'utf-8',
});
const output = result.stdout;
const errorLines = output.split('\n').filter(line => line.includes('error'));
assert(errorLines.length > 4);
});

test('should work with ECMAScript modules config', async t => {
const result = spawn.sync('npx', ['eslint', '-c', 'eslint.config.mjs', 'file.js'], {
cwd: __dirname,
encoding: 'utf-8',
});
const output = result.stdout;
const errorLines = output.split('\n').filter(line => line.includes('error'));
assert(errorLines.length > 4);
});
12 changes: 12 additions & 0 deletions its/eslint-plugin-sonarjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "eslint-plugin-sonarjs-tests",
"description": "Test suite for eslint-plugin-sonarjs",
"scripts": {
"build": "npm install && cp ../../packages/jsts/src/rules/lib/eslint-plugin-sonarjs-* ./plugin.tgz && npm i ./plugin.tgz --no-save && rm -f plugin.tgz",
"test": "node index.test.js"
},
"devDependencies": {
"cross-spawn": "7.0.3",
"eslint": "8.57.0"
}
}
Loading

0 comments on commit 3f97c77

Please sign in to comment.