2016-06-22 15:02:59 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-14 21:44:53 +01:00
|
|
|
const __hasOwnProperty = Object.prototype.hasOwnProperty;
|
2016-06-22 15:02:59 +02:00
|
|
|
|
2016-09-17 16:28:28 +02:00
|
|
|
// Checks that each rule is defined only once.
|
2018-01-30 03:38:49 +01:00
|
|
|
function reportDuplicateRules( ast, session ) {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
|
|
|
const rules = {};
|
|
|
|
|
2018-01-30 03:38:49 +01:00
|
|
|
const check = session.buildVisitor( {
|
2017-10-25 20:19:42 +02:00
|
|
|
rule( node ) {
|
|
|
|
|
|
|
|
const name = node.name;
|
|
|
|
|
2018-01-14 21:44:53 +01:00
|
|
|
if ( __hasOwnProperty.call( rules, name ) ) {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
|
|
|
const start = rules[ name ].start;
|
|
|
|
|
2018-02-02 05:32:39 +01:00
|
|
|
session.error(
|
2017-10-25 20:19:42 +02:00
|
|
|
`Rule "${ name }" is already defined at line ${ start.line }, column ${ start.column }.`,
|
|
|
|
node.location
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rules[ node.name ] = node.location;
|
|
|
|
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
check( ast );
|
|
|
|
|
2016-06-22 15:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = reportDuplicateRules;
|