mirror of
https://github.com/wassname/talk.git
synced 2026-07-07 15:45:44 +08:00
lint
This commit is contained in:
@@ -3,7 +3,7 @@ const _ = require('lodash');
|
||||
const natural = require('natural');
|
||||
const tokenizer = new natural.WordTokenizer();
|
||||
const Setting = require('../models/setting');
|
||||
const errors = require('../errors');
|
||||
const Errors = require('../errors');
|
||||
|
||||
/**
|
||||
* The root wordlist object.
|
||||
@@ -144,7 +144,7 @@ class Wordlist {
|
||||
if (this.match(this.lists.banned, phrase)) {
|
||||
debug(`the field "${field}" contained a phrase "${phrase}" which contained a banned word/phrase`);
|
||||
|
||||
errors.banned = errors.ErrContainsProfanity;
|
||||
errors.banned = Errors.ErrContainsProfanity;
|
||||
|
||||
// Stop looping through the fields now, we discovered the worst possible
|
||||
// situation (a banned word).
|
||||
@@ -155,7 +155,7 @@ class Wordlist {
|
||||
if (this.match(this.lists.suspect, phrase)) {
|
||||
debug(`the field "${field}" contained a phrase "${phrase}" which contained a suspected word/phrase`);
|
||||
|
||||
errors.suspect = errors.ErrContainsProfanity;
|
||||
errors.suspect = Errors.ErrContainsProfanity;
|
||||
|
||||
// Continue looping through the fields now, we discovered a possible bad
|
||||
// word (suspect).
|
||||
@@ -174,13 +174,14 @@ class Wordlist {
|
||||
return wl.load()
|
||||
.then(() => {
|
||||
displayName = displayName.replace(/_/g, '');
|
||||
|
||||
// test each word, and fail if we find a match
|
||||
const hasBadWords = wl.lists.banned.some(word => {
|
||||
return new RegExp(word, 'ig').test(displayName);
|
||||
});
|
||||
|
||||
if (hasBadWords) {
|
||||
throw errors.ErrContainsProfanity;
|
||||
throw Errors.ErrContainsProfanity;
|
||||
} else {
|
||||
return Promise.resolve(displayName);
|
||||
}
|
||||
@@ -216,6 +217,4 @@ class Wordlist {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = Wordlist;
|
||||
|
||||
Reference in New Issue
Block a user