Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Procházka Václav committed Jan 12, 2024
1 parent d96b0dc commit 709acc7
Show file tree
Hide file tree
Showing 8 changed files with 8,842 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to NPM
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies and build 🔧
run: npm ci && npm run build
- name: Publish package on NPM 📦
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.DS_Store
node_modules
dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# eslint-plugin-sentences
eslint plugin to warn prohibit sentences in code

Prohibit words, sentences in code & comments.

## Installation

Install [ESLint](https://github.com/eslint/eslint) either locally or globally.

```bash
npm install --save-dev eslint
```

```bash
npm install --save-dev eslint-plugin-sentences
```

## Configuration via .eslintrc

```js
{
"plugins": [
"sentences"
],
"rules": {
"sentences/no-sentences": [`error`, ['prohibit sentence']]
}
}
```
46 changes: 46 additions & 0 deletions lib/__test__/no-sentences.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const rule = require("../rules/no-sentences");
RuleTester = require("eslint").RuleTester;

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: "module", } });

ruleTester.run("no-sentences", rule, {
valid: [
{
code: `
// code
var x = 5;
`,
options: ['forbidden code'],
},
{
code: `
// code
var x = 5;
`,
options: ['xz', 'xx'],
}
],

invalid: [
{
code: `
// forbidden code
var forbiddenCode = 34
`,
errors: [{
message: 'Avoid using the specified sentence in the code',
}],
options: ['forbidden code'],
},
{
code: `
// code
var forbiddenCode = 34
`,
errors: [{
message: 'Avoid using the specified sentence in the code',
}],
options: ['forbidden code' ,'forbiddenCode'],
},
]
})
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const noSentencesRule = require("./rules/no-sentences");
const plugin = { rules: { "no-sentences": noSentencesRule } };
module.exports = plugin;
31 changes: 31 additions & 0 deletions lib/rules/no-sentences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallow the specified sentence',
},
schema: {
type: "array",
items: {
string: ["always", "never"]
},
}
},
create: function (context) {
return {
Program: function (node) {
const code = context.sourceCode.getText();
const comments = context.sourceCode.getAllComments();

context.options.forEach((option) => {
if (code.includes(option) || comments.includes(option)) {
context.report({
node,
message: 'Avoid using the specified sentence in the code',
});
}
})
}
}
}
}
Loading

0 comments on commit 709acc7

Please sign in to comment.