Skip to content

Commit

Permalink
chore(ci): add github actions
Browse files Browse the repository at this point in the history
1. fix tests with new api
  • Loading branch information
rajasegar committed Jun 8, 2021
1 parent f13b9f3 commit 0175b1c
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 18 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,67 @@
name: CI

on:
push:
branches:
- master
- main
- 'v*' # older version branches
tags:
- '*'
pull_request: {}
schedule:
- cron: '0 6 * * 0' # weekly, on sundays

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: install dependencies
run: yarn install --frozen-lockfile
- name: linting
run: yarn lint

test:
name: Tests
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"

strategy:
matrix:
node: ['12', '14', '16']

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: install dependencies
run: yarn install --frozen-lockfile
- name: test
run: yarn test --coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

floating-test:
name: Floating dependencies
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: install dependencies
run: yarn install --no-lockfile
- name: test
run: yarn test
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
node_modules
pnpm-debug.log
coverage/
85 changes: 76 additions & 9 deletions README.md
Expand Up @@ -8,7 +8,7 @@ npm install jscodeshift-collections
```

## Usage
```
```js
const jscsCollections = require('jscodeshift-collections');

module.exports = function(fileInfo, api) {
Expand All @@ -27,18 +27,19 @@ module.exports = function(fileInfo, api) {

Say for example, if you want to rename a function declaration `foo` to `bar`

### Transform with new Collection API
```js
j.findFunctionDeclarations('foo')
.renameTo('bar')
```

### Before

```js
function foo() {
}
```

### Codemod with new Collection API
```js
j.findFunctionDeclarations('foo')
.renameTo('bar')
```

### After

Expand All @@ -47,6 +48,72 @@ function bar() {
}
```

## List of Collection:
- FunctionDeclaration
- CallExpression
## List of Collections:

### FunctionDeclaration

```js
// Find all function declarations
j.findFunctionDeclarations()

// Find all function declarations with name=foo and rename them to bar
j.findFunctionDeclarations('foo')
.renameTo('xyz');

// Find and remove params
j.findFunctionDeclarations('bar')
.removeParam('a');

// Find and add params
j.findFunctionDeclarations('bar')
.addParam('d');
```

### CallExpression

```js
// Find all call expressions
j.findCallExpressions();

// Find all member expressions
j.findCallExpressions('foo.bar');


// Find all nested member expressions
j.findCallExpressions('foo.bar.baz');

// Find and rename call expressions
j.findCallExpressions('foo')
.renameTo('xyz');

// Find and rename member expressions
j.findCallExpressions('foo')
.renameTo('foo.bar');

// Find and remove params
j.findCallExpressions('bar')
.removeParam('a');

// Find and add params
j.findCallExpressions('bar')
.addParam('d');
```

### ImportDeclaration

```js
// Find all import declarations
j.findImportDeclarations();

// Find and rename
j.findImportDeclarations('a')
.renameTo('xyz');

// Find and remove specifiers
j.findImportDeclarations('a')
.removeSpecifier('a');

// Find and add specifiers
j.findImportDeclarations('a')
.addSpecifier('c');
```
2 changes: 1 addition & 1 deletion collections/CallExpression.js
Expand Up @@ -76,7 +76,7 @@ const transformMethods = {
removeParam(param) {
return this.forEach((path) => {
const newParams = path.value.arguments.filter((p) => p.name !== param);
path.value.arguments = newParams;
path.value.arguments = newParams; // eslint-disable-line
});
},
};
Expand Down
4 changes: 1 addition & 3 deletions collections/__tests__/CallExpression-test.js
@@ -1,11 +1,9 @@
const Collection = require('jscodeshift/src/Collection');
const recast = require('recast');

const types = recast.types.namedTypes;

const CallExpressionCollection = require('../CallExpression');

CallExpressionCollection.register();
CallExpressionCollection.register(Collection);

test('find all call expressions', () => {
const nodes = [recast.parse(
Expand Down
2 changes: 1 addition & 1 deletion collections/__tests__/FunctionDeclaration-test.js
Expand Up @@ -6,7 +6,7 @@ const types = recast.types.namedTypes;

const FunctionDeclarationCollection = require('../FunctionDeclaration');

FunctionDeclarationCollection.register();
FunctionDeclarationCollection.register(Collection);

test('find all function declarations', () => {
const nodes = [recast.parse(
Expand Down
4 changes: 2 additions & 2 deletions collections/__tests__/ImportDeclaration-test.js
Expand Up @@ -3,9 +3,9 @@ const recast = require('recast');

const ImportDeclarationCollection = require('../ImportDeclaration');

ImportDeclarationCollection.register();
ImportDeclarationCollection.register(Collection);

test('find all function declarations', () => {
test('find all import declarations', () => {
const nodes = [recast.parse(
'function foo() {}',
'import a from "a"',
Expand Down
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -4,8 +4,10 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "jest",
"release": "release-it"
"test": "jest --coverage",
"release": "release-it",
"deploy": "git push && git push --tags && npm publish",
"lint": "eslint ."
},
"keywords": [],
"author": "Rajasegar Chandran",
Expand Down

0 comments on commit 0175b1c

Please sign in to comment.