-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fab54f2
Showing
7 changed files
with
475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Debug log from npm | ||
npm-debug.log | ||
|
||
|
||
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
# if you remove the above rule, at least ignore the following: | ||
|
||
# User-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# .idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
# .idea/uiDesigner.xml | ||
|
||
# Gradle: | ||
# .idea/gradle.xml | ||
# .idea/libraries | ||
|
||
# Mongo Explorer plugin: | ||
# .idea/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
||
|
||
/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: "stable" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2017 azu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# textlint-rule-period-in-list-item [](https://textlint.github.io/) | ||
|
||
textlint rule that check with or without period in list item. | ||
|
||
**Default** | ||
|
||
No period mark at end of the list item. | ||
You can change the behavior by options. | ||
|
||
**OK**: | ||
|
||
``` | ||
- item | ||
``` | ||
|
||
**NG**: | ||
|
||
``` | ||
- item. | ||
``` | ||
|
||
|
||
## Install | ||
|
||
Install with [npm](https://www.npmjs.com/): | ||
|
||
npm install textlint-rule-period-in-list-item | ||
|
||
## Usage | ||
|
||
Via `.textlintrc`(Recommended) | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"period-in-list-item": true | ||
} | ||
} | ||
``` | ||
|
||
Via CLI | ||
|
||
``` | ||
textlint --rule period-in-list-item README.md | ||
``` | ||
|
||
## Options | ||
|
||
```json | ||
{ | ||
// prefer to use period mark. | ||
// "" (default is no period) | ||
// You can select period mark like "." from "periodMarks". | ||
"periodMark": "", | ||
// Built-in recognized period mark list | ||
// if the period of the text is not `periodMark` and it is a string in the `periodMarks`, | ||
"periodMarks": [".", "。", "."], | ||
// allow exception period mark list at end of the list item | ||
// Ignore this period mark | ||
"allowPeriodMarks": [], | ||
// Allow emoji at end of the list item | ||
"allowEmoji": false, | ||
// If not exist `periodMark` at end of the list item | ||
// Automatically, append `periodMark` when does textlint --fix | ||
"forceAppendPeriod": false | ||
} | ||
``` | ||
|
||
## Example | ||
|
||
Use `.` as period mark at end of the list item. | ||
Automatically, force append periodMark. | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"period-in-list-item": { | ||
"periodMark": ".", | ||
"forceAppendPeriod": true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Before** | ||
|
||
``` | ||
-item | ||
<!-- Not exist period mark(".") at end of list item. --> | ||
``` | ||
|
||
**After** | ||
|
||
`textlint --fix` fixes this issue. | ||
|
||
``` | ||
- item. | ||
``` | ||
|
||
## Changelog | ||
|
||
See [Releases page](https://github.com/azu/textlint-rule-period-in-list-item/releases). | ||
|
||
## Running tests | ||
|
||
Install devDependencies and Run `npm test`: | ||
|
||
npm i -d && npm test | ||
|
||
## Contributing | ||
|
||
Pull requests and stars are always welcome. | ||
|
||
For bugs and feature requests, [please create an issue](https://github.com/azu/textlint-rule-period-in-list-item/issues). | ||
|
||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -am 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D | ||
|
||
## Author | ||
|
||
- [github/azu](https://github.com/azu) | ||
- [twitter/azu_re](https://twitter.com/azu_re) | ||
|
||
## License | ||
|
||
MIT © azu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"author": "azu", | ||
"license": "MIT", | ||
"files": [ | ||
"bin/", | ||
"lib/", | ||
"src/" | ||
], | ||
"name": "textlint-rule-period-in-list-item", | ||
"version": "1.0.0", | ||
"description": "textlint rule that check with or without period in list item.", | ||
"main": "lib/textlint-rule-period-in-list-item.js", | ||
"scripts": { | ||
"test": "textlint-scripts test", | ||
"prepublish": "npm run --if-present build", | ||
"build": "textlint-scripts build", | ||
"watch": "textlint-scripts build --watch" | ||
}, | ||
"keywords": [ | ||
"textlintrule" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/azu/textlint-rule-period-in-list-item.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/azu/textlint-rule-period-in-list-item/issues" | ||
}, | ||
"homepage": "https://github.com/azu/textlint-rule-period-in-list-item", | ||
"devDependencies": { | ||
"textlint-scripts": "^1.2.2" | ||
}, | ||
"dependencies": { | ||
"check-ends-with-period": "^1.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// MIT © 2017 azu | ||
"use strict"; | ||
const checkEndsWithPeriod = require("check-ends-with-period"); | ||
const defaultOptions = { | ||
// prefer to use period mark. | ||
// "" (default is no period) | ||
// You can select period mark like "." from "periodMarks". | ||
"periodMark": "", | ||
// Built-in recognized period mark list | ||
// if the period of the text is not `periodMark` and it is a string in the `periodMarks`, | ||
"periodMarks": [".", "。", "."], | ||
// allow exception period mark list at end of the list item | ||
// Ignore this period mark | ||
"allowPeriodMarks": [], | ||
// Allow emoji at end of the list item | ||
"allowEmoji": false, | ||
// If not exist `periodMark` at end of the list item | ||
// Automatically, append `periodMark` when does textlint --fix | ||
"forceAppendPeriod": false | ||
}; | ||
const reporter = (context, options = {}) => { | ||
const { Syntax, RuleError, report, fixer, getSource } = context; | ||
const preferPeriodMark = options.periodMark || defaultOptions.periodMark; | ||
const isNotNeededPeriodMark = preferPeriodMark === ""; | ||
const periodMarks = (options.periodMarks || defaultOptions.periodMarks).concat(preferPeriodMark); | ||
const allowPeriodMarks = options.allowPeriodMarks !== undefined | ||
? options.allowPeriodMarks | ||
: defaultOptions.allowPeriodMarks; | ||
const allowEmoji = options.allowEmoji !== undefined | ||
? options.allowEmoji | ||
: defaultOptions.allowEmoji; | ||
const forceAppendPeriod = options.forceAppendPeriod !== undefined | ||
? options.forceAppendPeriod | ||
: defaultOptions.forceAppendPeriod; | ||
return { | ||
[Syntax.ListItem](node){ | ||
const text = getSource(node); | ||
const { valid, periodMark, index } = checkEndsWithPeriod(text, { | ||
periodMarks, | ||
allowPeriodMarks, | ||
allowEmoji, | ||
}); | ||
// Prefer no needed period, but exist period | ||
if (isNotNeededPeriodMark) { | ||
if (valid) { | ||
// should be remove period mark | ||
report(node, new RuleError(`Should remove period mark("${periodMark}") at end of list item.`, { | ||
index, | ||
fix: fixer.replaceTextRange([index, index + periodMark.length], "") | ||
})); | ||
return; | ||
} | ||
} else { | ||
// Prefer to use period | ||
if (valid) { | ||
// but exist difference period | ||
if (periodMark === preferPeriodMark) { | ||
return; | ||
} | ||
report(node, new RuleError(`Prefer to use period mark("${preferPeriodMark}") at end of list item.`, { | ||
index, | ||
fix: fixer.replaceTextRange([index, index + periodMark.length], preferPeriodMark) | ||
})); | ||
return; | ||
} else { | ||
// but not exist period | ||
if (forceAppendPeriod) { | ||
report(node, new RuleError(`Not exist period mark("${preferPeriodMark}") at end of list item.`, { | ||
index, | ||
fix: fixer.replaceTextRange([index + 1, index + 1], preferPeriodMark) | ||
})); | ||
} else { | ||
report(node, new RuleError(`Not exist period mark("${preferPeriodMark}") at end of list item.`, { | ||
index | ||
})) | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
}; | ||
module.exports = { | ||
linter: reporter, | ||
fixer: reporter | ||
}; |
Oops, something went wrong.