Skip to content

Commit

Permalink
Merge pull request #1 from salesforce/scaffold
Browse files Browse the repository at this point in the history
Setup eslint plugin scaffold and basic CI actions
  • Loading branch information
ben-zhang-at-salesforce committed May 6, 2024
2 parents 70357b7 + c5f1afd commit c6516ad
Show file tree
Hide file tree
Showing 17 changed files with 5,345 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"env": {
"jest": true,
"node": true
},
"rules": {
"strict": ["error", "global"]
},
"ignorePatterns": ["test/**/test.js"]
}
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: lint
run-name: Installs project and runs linting
on: [ push, pull_request ]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18, 20 ]
name: Linting on Ubuntu with Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm install
- run: npm run lint
18 changes: 18 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: prettier
run-name: Installs project and runs prettier checks
on: [ push, pull_request ]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18, 20 ]
name: Prettier on Ubuntu with Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm install
- run: npm run format
32 changes: 32 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: run-tests
run-name: Installs project and runs tests
on: [ push, pull_request ]
jobs:
run-tests-nix:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18, 20 ]
name: Run tests on Ubuntu with Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm install
- run: npm run test
run-tests-win:
runs-on: windows-latest
strategy:
matrix:
node: [ 18, 20 ]
name: Run tests on Windows with Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm install
- run: npm run test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/reports
test-report.xml
junit.xml

20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Comment line immediately above ownership line is reserved for related other information. Please be careful while editing.
#ECCN:Open Source
* @khawkins @sfdctaka @maliroteh-sf
* @khawkins @sfdctaka @maliroteh-sf @ben-zhang-at-salesforce @haifeng-li-at-salesforce
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# @salesforce/eslint-plugin-lwc-mobile
# @salesforce/eslint-plugin-lwc-mobile

## Installation

To add this plugin to your package/project, install it with your favorite Node.js package manager.

### yarn

```sh
$ yarn add --dev @salesforce/eslint-plugin-lwc-mobile
```

### npm

```sh
$ npm install --save-dev @salesforce/eslint-plugin-lwc-mobile
```

## Configuration

Here's an example snippet of a `.eslintrc.json` configuration file, that will configure the `eslint-plugin-lwc-mobile` plugin. Extending the `plugin:@salesforce/lwc-mobile/recommended` ESLint configuration will enable static analysis on all `.js` files used in your Lightning web components.

```json
{
"extends": ["eslint:recommended", "plugin:@salesforce/lwc-mobile/recommended"]
}
```
35 changes: 35 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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
*/

'use strict';

module.exports = {
displayName: 'Unit Tests',
setupFilesAfterEnv: ['jest-extended', 'jest-chain'],
testMatch: [
'<rootDir>/test/plugin.js',
'<rootDir>/test/lib/rules/**/*.js',
'!**/test/lib/rules/shared.js'
],
moduleFileExtensions: ['js', 'json'],
testResultsProcessor: 'jest-sonar-reporter',
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/lib/'],
moduleDirectories: ['node_modules'],
collectCoverage: true,
collectCoverageFrom: ['lib/**/*.js'],
coverageDirectory: 'reports/coverage',
reporters: [
'default',
[
'jest-junit',
{
suiteName: 'Unit Tests',
output: './reports/junit/jest-results.xml'
}
]
]
};
12 changes: 12 additions & 0 deletions lib/configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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
*/

'use strict';

module.exports = {
plugins: ['@salesforce/lwc-mobile']
};
15 changes: 15 additions & 0 deletions lib/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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
*/

'use strict';

module.exports = {
extends: ['./configs/base'],
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': 'warn'
}
};
23 changes: 23 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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
*/

'use strict';

const base = require('./configs/base');
const recommended = require('./configs/recommended');

const enforceFooBar = require('./rules/enforce-foo-bar');

module.exports = {
rules: {
'enforce-foo-bar': enforceFooBar
},
config: {
base,
recommended
}
};
60 changes: 60 additions & 0 deletions lib/rules/enforce-foo-bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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
*/

'use strict';

// TODO: This sample rule would be removed.
// The enforce-foo-bar rule definition
module.exports = {
meta: {
type: 'problem',
docs: {
description:
"Enforce that a variable named `foo` can only be assigned a value of 'bar'."
},
fixable: 'code',
schema: []
},
create(context) {
return {
// Performs action in the function on every variable declarator
VariableDeclarator(node) {
// Check if a `const` variable declaration
if (node.parent.kind === 'const') {
// Check if variable name is `foo`
if (node.id.type === 'Identifier' && node.id.name === 'foo') {
// Check if value of variable is "bar"
if (
node.init &&
node.init.type === 'Literal' &&
node.init.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,
message:
'Value other than "bar" assigned to `const foo`. Unexpected value: {{ notBar }}.',
data: {
notBar: node.init.value
},
fix(fixer) {
return fixer.replaceText(node.init, '"bar"');
}
});
}
}
}
}
};
}
};
Loading

0 comments on commit c6516ad

Please sign in to comment.